답안 #171937

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171937 2019-12-30T16:33:55 Z ToniB Rasvjeta (COCI17_rasvjeta) C++14
50 / 50
2 ms 376 KB
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    
    int ulica[n] = {0};
    
    for(int i = 0; i < m; ++i){
    	int s;
    	cin >> s;
    	s -= 1;
    	
    	for(int j = (s - k); j <= (s + k); ++j){
    		
    		if(j >= 0 and j < n) ulica[j] = 1;
		}
	}
	
	int coord1 = -1, coord2 = 0;
	int len = 0, sol = 0;
	
	for(int i = 0; i < n; ++i){
	    if(ulica[i] == 0 and coord1 == -1){
	    	coord1 = i;
	    	len = 1;
		}
		else if(ulica[i] == 0 and coord1 != -1){
			len += 1;
		}
		else if(ulica[i] == 1 and coord1 != -1){
			coord2 = i;
			int uk = 0;
			
			uk = len / (2 * k + 1);
			
			if(len % (2 * k + 1) != 0) uk++;
			
			sol += uk;
			coord2 = coord1 + (uk * (2 * k + 1));
			
			for(int j = coord1; j <= coord2; ++j){
				ulica[j] = 1;
			}
			
			coord1 = -1;
			coord2 = 0;
			len = 0;
			
		}
	}
	
	if(len != 0){
		sol += (len / (2 * k + 1));
		
		if(len % (2 * k + 1) != 0) sol++;
	}
	
	cout << sol;
    
    

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 348 KB Output is correct