Submission #1291758

#TimeUsernameProblemLanguageResultExecution timeMemory
1291758julia_08Comparing Plants (IOI20_plants)C++20
0 / 100
2 ms584 KiB
#include <bits/stdc++.h>
#include "plants.h"

using namespace std;

const int MAXN = 5e3 + 10;

int cmp[MAXN][MAXN];

void init(int k, vector<int> r){

	int n = (int) r.size();

	for(int i=1; i<k; i++){

		for(int j=0; j<n; j++){

			int x = j, y = (j + i) % n;

			if(r[x] > r[y]){

				cmp[x][y] = -1;
				cmp[y][x] = 1;

			} else if(r[x] < r[y]){

				cmp[x][y] = 1;
				cmp[y][x] = -1;

			} else{

				// caso chato

				int z = (y + k - 1) % n;

				// nao pode ter igualdade

				if(cmp[z][x] == 1){

					// (z, x) = -1
					cmp[y][x] = -1;
					// (x, z) = 1
					cmp[x][y] = 1;


				} else if(cmp[z][x] == -1){

					cmp[y][x] = 1;
					cmp[x][y] = -1;

				}

			}

		}

		for(int j=0; j<n; j++){
			if(cmp[j][(j + i) % n] == -1){
				r[j] --;
			}
		}

	}

	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i != j){
				assert(cmp[i][j] != 0);
			}
		}
	}

}

int compare_plants(int x, int y){
	return cmp[x][y];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...