Submission #679493

# Submission time Handle Problem Language Result Execution time Memory
679493 2023-01-08T12:15:20 Z stevancv KOVANICE (COI15_kovanice) C++14
0 / 100
154 ms 49380 KB
#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[s][y]) return;
    was[s][y] = 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++) {
        if (!was[i][0]) Dfs(Find(i), 0);
        if (!was[i][1]) Dfs(Find(i), 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

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 time Memory Grader output
1 Runtime error 20 ms 29148 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 51 ms 36664 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 32852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 154 ms 49380 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -