Cod sursa(job #1987202)

Utilizator DruffbaumPopescu Vlad Druffbaum Data 29 mai 2017 21:58:08
Problema Congr Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <cstdio>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>

typedef long long i64;
const int MAXN = 3e6;
#define BUF_SIZE 8192

FILE *f;
int v[2 * MAXN], sol[2 * MAXN];
char buf[BUF_SIZE];
int pos = BUF_SIZE;

inline char getChar() {
  if (pos == BUF_SIZE) {
    fread(buf, 1, BUF_SIZE, f);
    pos = 0;
  }
  return buf[pos++];
}

inline int read() {
  int result = 0;
  char c;
  do {
    c = getChar();
  } while (!isdigit(c));
  do {
    result = 10 * result + c - '0';
    c = getChar();
  } while (isdigit(c));
  return result;
}

void swap(int &a, int &b) {
  a = a ^ b;
  b = a ^ b;
  a = a ^ b;
}

int main() {
  srand(time(NULL));
  int n;
  i64 s;
  f = fopen("congr.in", "r");
  n = read();
  s = 0;
  for (int i = 1; i <= 2 * n; ++i) {
    v[i] = read();
    if (i <= n) {
      s += v[i];
    }
    sol[i] = i;
  }
  fclose(f);
  while (s % n) {
    int x = 1 + rand() % n;
    int y = n + rand() % n;
    if (y == n) {
      ++y;
    }
    s = s - v[x] + v[y];
    swap(v[x], v[y]);
    swap(sol[x], sol[y]);
  }
  f = fopen("congr.out", "w");
  for (int i = 1; i <= n; ++i) {
    fprintf(f, "%d ", sol[i]);
  }
  fclose(f);
  return 0;
}