제출 #601268

#제출 시각아이디문제언어결과실행 시간메모리
601268yutabi식물 비교 (IOI20_plants)C++14
14 / 100
4051 ms8668 KiB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;


#define pb push_back


int n;
vector <int> ans;

void init(int k, std::vector<int> r)
{
	n=r.size();

	ans=vector <int> (n);

	for(int i=0;i<n;i++)
	{
		int loc;
		int last=-1;

		for(int j=n-k;j<n;j++)
		{
			if(r[j]==0)
			{
				last=j;
			}
		}

		for(int j=0;j<n;j++)
		{
			if(r[j]==0)
			{
				if(last==-1 || (last<j && last+k<=j) || (last>j && j+n-k>=last) || j==last)
				{
					loc=j;

					break;
				}

				last=j;
			}
		}

		r[loc]=n*4;

		ans[loc]=i;

		for(int j=(loc-k+1+n)%n;j!=loc;j=(j+1)%n)
		{
			r[j]--;
		}

		/*for(int j=0;j<n;j++)
		{
			printf("%d ",r[j]);
		}

		printf("\n");*/
	}

	return;
}

int compare_plants(int x, int y)
{
	if(ans[x]<ans[y])
	{
		return 1;
	}

	return -1;
}

컴파일 시 표준 에러 (stderr) 메시지

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:46:8: warning: 'loc' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |   r[loc]=n*4;
      |        ^
#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...