답안 #145487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145487 2019-08-20T08:55:31 Z charlies_moo Rasvjeta (COCI17_rasvjeta) C++
10 / 50
3 ms 384 KB
#include <iostream>
using namespace std;
int main(){
	int n,l,k;
	cin>>n>>k>>l;
	int light[n+1];
	int s;
	for(int i=1;i<=n;i++){
		light[i]=0;
	}
	for(int i=0;i<k;i++){
		cin>>s;
		for(int j=s-k;j<=s+k;j++){
			if(j>=1&&j<=n){
				light[j]=1;
			}
		}
	}
	//for(int i=1;i<=n;i++){
		//cout<<light[i]<<" ";
	//}
	int flag=0;
	int time=0;
	while(flag==0){
		int flag2=0;
		int biggest=0;
		int seat;
		for(int i=1;i<=n;i++){
			if(light[i]==0){
				flag2=1;
			}
		}
		if(flag2==1){
			time++;
			for(int i=1;i<=n;i++){
				int tot=0;
				if(light[i]==0){
					for(int j=i-k;j<=i+k;j++){
						if(j>=1&&j<=n){
							if(light[j]==0){
								tot++;
							}
						}
					}
				}
				if(tot>biggest){
					biggest=tot;
					seat=i;
				}
			}
			for(int i=seat-k;i<=seat+k;i++){
				if(i>=1&&i<=n){
					light[i]=1;
				}
			}
		}
		else{
			flag=1;
		}
	}
	cout<<time;
} 

Compilation message

rasjveta.cpp: In function 'int main()':
rasjveta.cpp:51:12: warning: 'seat' may be used uninitialized in this function [-Wmaybe-uninitialized]
    for(int i=seat-k;i<=seat+k;i++){
            ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Incorrect 3 ms 376 KB Output isn't correct
5 Incorrect 2 ms 380 KB Output isn't correct
6 Incorrect 2 ms 256 KB Output isn't correct
7 Incorrect 2 ms 256 KB Output isn't correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Incorrect 3 ms 380 KB Output isn't correct