답안 #442809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442809 2021-07-09T07:38:28 Z sstefanovic Trobojnica (COCI19_trobojnica) C++17
0 / 110
1 ms 204 KB
#include<bits/stdc++.h>
using namespace std; 

const int MAXN = 2e5+10; 
int n; 
string s;
int slj[MAXN], boje[MAXN], cnt[3], solx[MAXN], soly[MAXN], solb[MAXN]; 

int main( ){
	cin >> n >> s; 
	for (int i=0; i<n; i++){
		boje[i]=s[i]-'1'; 
		cnt[boje[i]]++;
		slj[i] = (i+1)%n; 
	}
	int x=0; 
	for (int i=0; i<n-3; i++){
		if (max (cnt[0], max(cnt[1], cnt[2])) == n-i){
			cout << "NE\n"; 
			return 0;
		}
		while (boje[x] == boje [slj[x]] or cnt[boje[x]] == 1 && cnt[boje[slj[x]]]){
			x = slj[x]; 
		}
		int y = slj [x]; 
		int nX = 3-boje[x]-boje[y]; 
		cnt[boje[x]]--; 
		cnt[boje[y]]--; 
		cnt[nX]++; 
		solx[i]=x; 
		soly[i]=slj[y]; 
		solb[i]=nX; 
		boje[x] = nX; 
		slj[x]=slj[y]; 
	}
	if (cnt[0] == 1 && cnt[1]==1 && cnt[2] == 1){
		cout << "DA\n"; 
		for (int i=0; i<n-3; i++){
			cout << solx[i] << " " << soly[i] <<" " << solb[i] << endl; 
		}
	}else{
		cout << "NE\n";
	}
	return 0;
}

Compilation message

trobojnica.cpp: In function 'int main()':
trobojnica.cpp:22:56: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   22 |   while (boje[x] == boje [slj[x]] or cnt[boje[x]] == 1 && cnt[boje[slj[x]]]){
      |                                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Integer parameter [name=X] equals to 0, violates the range [1, 8]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Integer parameter [name=X] equals to 0, violates the range [1, 8]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Integer parameter [name=X] equals to 0, violates the range [1, 8]
2 Halted 0 ms 0 KB -