Submission #241494

#TimeUsernameProblemLanguageResultExecution timeMemory
241494marlicuKOVANICE (COI15_kovanice)C++14
0 / 100
139 ms17656 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; int n, m, v; int pripada[MAXN]; vector <int> veze[MAXN]; bool ispisan[MAXN]; int vrsta[MAXN]; void init() { for (int i = 1; i <= m; i++) { pripada[i] = i; } } void ispis() { for (int i = 1; i <= m; i++) { cout << pripada[i] << " "; } cout << '\n'; memset(ispisan, 0, sizeof(ispisan)); for (int i = 1; i <= m; i++) { if (ispisan[i]) continue; cout << i << " "; int t = i; while (veze[t].size()) { cout << veze[t][0] << " "; t = veze[t][0]; ispisan[t] = true; } cout << '\n'; ispisan[i] = true; } } void konacan_ispis() { int x; for (int i = 1; i <= m; i++) { x = pripada[i]; if (!vrsta[x]) cout << "?\n"; else cout << "K" << vrsta[x] << "\n"; } } void vaganje() { string s; cin >> s; int a, b = 0; char znak; unsigned t = -1; while (++t < s.size()) { if (s[t] == '=' || s[t] == '<') { znak = s[t]; a = b; b = 0; } else { b *= 10; b += (s[t] - '0'); } } //cout << a << " " << znak << " " << b << '\n'; a = pripada[a]; b = pripada[b]; if (znak == '=') { if (a < b) pripada[b] = a; else pripada[a] = b; } else { veze[a].push_back(b); } //ispis(); } void odredivanje() { vector <int> niz; memset(ispisan, 0, sizeof(ispisan)); for (int i = 1; i <= m; i++) { int t = pripada[i]; if (ispisan[t]) continue; ispisan[t] = true; niz.clear(); niz.push_back(t); while (veze[t].size()) { t = veze[t][0]; ispisan[t] = true; niz.push_back(t); } /* cout << niz.size() << " : "; for (auto x : niz) { cout << x << " "; } cout << '\n'; */ if (niz.size() == n) { for (int j = 0; j < n; j++) { vrsta[niz[j]] = j + 1; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> v; init(); for (int i = 0; i < v; i++) { vaganje(); } odredivanje(); konacan_ispis(); return 0; }

Compilation message (stderr)

kovanice.cpp: In function 'void odredivanje()':
kovanice.cpp:113:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (niz.size() == n) {
             ~~~~~~~~~~~^~~~
kovanice.cpp: In function 'void vaganje()':
kovanice.cpp:77:5: warning: 'znak' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (znak == '=') {
     ^~
kovanice.cpp:74:7: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
     a = pripada[a];
     ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...