Submission #442811

#TimeUsernameProblemLanguageResultExecution timeMemory
442811sstefanovicTrobojnica (COCI19_trobojnica)C++14
60 / 110
2071 ms3952 KiB
#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]+1 << " " << soly[i]+1 <<" " << solb[i]+1 << endl; } }else{ cout << "NE\n"; return 0; } return 0; }

Compilation message (stderr)

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]]]){
      |                                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...