Submission #679499

#TimeUsernameProblemLanguageResultExecution timeMemory
679499stevancvKOVANICE (COI15_kovanice)C++14
0 / 100
145 ms56516 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) #define sadd(a, b) a = Add(a, b) #define smul(a, b) a = Mul(a, b) using namespace std; const int N = 3e5 + 2; const int mod = 1e9 + 7; int Convert(string s, int l, int r) { int ans = 0; for (int i = l; i <= r; i++) { ans = 10 * ans + (s[i] - '0'); } return ans; } int link[N], mx[2][N]; bool was[2][N]; vector<int> g[2][N]; int Find(int u) { if (u == link[u]) return u; return link[u] = Find(link[u]); } void Unite(int u, int v) { u = Find(u); v = Find(v); link[v] = u; } void Dfs(int s, int y) { if (was[y][s]) return; was[y][s] = 1; for (int u : g[y][s]) { Dfs(u, y); smax(mx[y][s], mx[y][u] + 1); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, v; cin >> n >> m >> v; for (int i = 1; i <= m; i++) link[i] = i; vector<array<int, 2>> e; for (int i = 0; i < v; i++) { string s; cin >> s; int pos = -1; for (int j = 0; j < s.size(); j++) { if (!('0' <= s[j] && s[j] <= '9')) pos = j; } int x = Convert(s, 0, pos - 1); int y = Convert(s, pos + 1, s.size() - 1); if (s[pos] == '=') Unite(x, y); if (s[pos] == '<') e.push_back({x, y}); if (s[pos] == '>') e.push_back({y, x}); } for (int i = 0; i < e.size(); i++) { int x = Find(e[i][0]); int y = Find(e[i][1]); g[0][x].push_back(y); g[1][y].push_back(x); } for (int i = 1; i <= m; i++) { int j = Find(i); if (!was[j][0]) Dfs(j, 0); if (!was[j][1]) Dfs(j, 1); } for (int i = 1; i <= m; i++) { int j = Find(i); if (mx[0][j] + mx[1][j] == n - 1) cout << 'K' << mx[1][j] + 1 << en; else cout << '?' << en; } return 0; }

Compilation message (stderr)

kovanice.cpp: In function 'int main()':
kovanice.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for (int j = 0; j < s.size(); j++) {
      |                         ~~^~~~~~~~~~
kovanice.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < e.size(); i++) {
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...