Submission #251458

#TimeUsernameProblemLanguageResultExecution timeMemory
251458BruteforcemanTrobojnica (COCI19_trobojnica)C++11
60 / 110
2086 ms4084 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; #define endl '\n' int suc[maxn]; int pre[maxn]; int succol[maxn], precol[maxn]; char s[maxn]; int main() { int n; scanf("%d", &n); scanf("%s", s); int freq[] = {0, 0, 0, 0}; for(int i = 0; i < n; i++) { pre[i] = (n + i - 1) % n; suc[i] = (i + 1) % n; freq[s[i] - '0'] += 1; precol[i] = s[pre[i]] - '0'; succol[i] = s[i] - '0'; } if(freq[1] == n || freq[2] == n || freq[3] == n) { puts("NE"); exit(0); } if(abs(freq[1] - freq[2]) % 2 == 1 || abs(freq[2] - freq[3]) % 2 == 1) { puts("NE"); exit(0); } puts("DA"); int cur = 0; for(int i = 0; i < n - 3; i++) { int occur = max({freq[1], freq[2], freq[3]}); int col; for(col = 1; col <= 3; col++) { if(freq[col] == occur) break; } while(true) { if(precol[cur] != succol[cur] && (col == precol[cur] || col == succol[cur])) { int inv = 6 - precol[cur] - succol[cur]; freq[precol[cur]] -= 1; freq[succol[cur]] -= 1; freq[inv] += 1; printf("%d %d %d\n", pre[cur] + 1, suc[cur] + 1, inv); pre[suc[cur]] = pre[cur]; precol[suc[cur]] = inv; suc[pre[cur]] = suc[cur]; succol[pre[cur]] = inv; cur = suc[cur]; break; } else { cur = suc[cur]; } } } return 0; }

Compilation message (stderr)

trobojnica.cpp: In function 'int main()':
trobojnica.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
trobojnica.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s);
   ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...