Submission #317529

#TimeUsernameProblemLanguageResultExecution timeMemory
317529arnold518Comparing Plants (IOI20_plants)C++14
14 / 100
277 ms8440 KiB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 5000;
const int INF = 1e9;

int N, K, R[MAXN+10], H[MAXN+10];

void init(int _K, vector<int> _R)
{
	K=_K; N=_R.size();
	for(int i=0; i<N; i++) R[i]=_R[i];

	for(int i=N-1; i>=0; i--)
	{
		vector<int> V;
		for(int j=0; j<N; j++) if(R[j]==0) V.push_back(j);
		//for(int j=0; j<N; j++) printf("%d ", R[j]); printf("\n");

		for(int j=0; j<V.size(); j++)
		{
			int p=V[j], q;
			if(j!=0) q=V[j-1];
			else q=V[V.size()-1];

			int d=(p-q+N)%N;
			if(d==0) d+=N;
			if(d>=K)
			{
				for(int k=(p-K+1+N)%N; k!=p; k=(k+1)%N) R[k]--;
				R[p]=INF;
				H[p]=i;
			}
		}
	}

	//for(int i=0; i<N; i++) printf("%d ", H[i]); printf("\n");
	return;
}

int compare_plants(int x, int y)
{
	int ans=0;
	if(H[x]>H[y]) return 1;
	if(H[x]<H[y]) return -1;
	return 0;
}

Compilation message (stderr)

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:25:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for(int j=0; j<V.size(); j++)
      |                ~^~~~~~~~~
plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:48:6: warning: unused variable 'ans' [-Wunused-variable]
   48 |  int ans=0;
      |      ^~~
#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...