Submission #316857

# Submission time Handle Problem Language Result Execution time Memory
316857 2020-10-28T11:06:07 Z spatarel Comparing Plants (IOI20_plants) C++17
0 / 100
0 ms 256 KB
#include "plants.h"
#include <stdio.h>

struct MoxRange {
  int mox;
  int l;
  int r;
};

MoxRange getMoxRange(int k, std::vector<int> &r) {
  int n = r.size();
  int i = n - 1;
  int positives = 0;
  while (r[i] != 0) {
    i--;
    positives++;
  }
  int maxPositives = -1;
  int maxZero = 0;
  for (int i = 0; i < (int)r.size(); i++) {
    if (r[i] == 0) {
      if (maxPositives < positives) {
        maxPositives = positives;
        positives = 0;
        maxZero = i;
      }
    } else {
      positives++;
    }
  }
  MoxRange answer;
  answer.mox = maxZero;
  answer.l = maxZero - maxPositives;
  answer.r = maxZero + k - 1;
  if (answer.r - answer.l + 1 > n) {
    answer.r = answer.l + n - 1;
  }
  answer.l = (answer.l + n) % n;
  answer.r = (answer.r + n) % n;
  
  r[maxZero] = -1;
  i = maxZero;
  for (int i = 0; i < k - 1; i++) {
    maxZero = (maxZero - 1 + n) % n;
    r[maxZero]--;
  }
	return answer;
}

void print(std::vector<int> &r) {
  int n = r.size();
  for (int i = 0; i < n; i++) {
    printf("%d ", r[i]);
  }
  printf("\n");
}

const int MAX_N = 300;

int gt[MAX_N][MAX_N];

void init(int k, std::vector<int> r) {
  int n = r.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      gt[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    //print(r);
    MoxRange moxRange = getMoxRange(k, r);
    //printf("%d > [%d..%d]\n", moxRange.mox, moxRange.l, moxRange.r);
    
    for (int x = moxRange.l; x != (moxRange.r + 1) % n; x = (x + 1) % n) {
      if (gt[x][moxRange.mox] == 0) {
        gt[moxRange.mox][x] = +1;
        gt[x][moxRange.mox] = -1;
      }
    }
  }
  /*
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      printf("%d ", gt[i][j]);
    }
    printf("\n");
  }//*/
  return;
}

int compare_plants(int x, int y) {
	return gt[x][y];
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -