Submission #846351

# Submission time Handle Problem Language Result Execution time Memory
846351 2023-09-07T13:56:45 Z vjudge1 KOVANICE (COI15_kovanice) C++17
50 / 100
2000 ms 28772 KB
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma optimize("AhmetEmreGurdal a.k.a. AEG")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native")
#define PB push_back
#define POB pop_back
#define ordered_set                              \
    tree<int, null_type, less<int>, rb_tree_tag, \
         tree_order_statistics_node_update>
#define int int64_t
#define F first
#define S second
#define I insert
#define sqr(a) ((a) * (a))
#define P pop
#define max3(a, b, c) (max(a, max(b, c)))
#define max4(a, b, c, d) (max(max(a, b), max(c, d)))
#define min3(a, b, c) (min(a, min(b, c)))
#define min4(a, b, c, d) (min(min(a, b), min(c, d)))
#define MOD 1000000007
#define mod 998244353
int binpow(int a, int p, int m = MOD) {
    int ans = 1;
    while (p) {
        if (p & 1) ans = ((ans % m) * (a % m)) % m;
        a = sqr(a) % m;
        p >>= 1;
    }
    return ans;
}
vector<vector<int>> adj2;
vector<int> typ;
int n, m, v;
bool dfs(int s, int pre) {
    bool ans = false;
    if (pre == n - 1) {
        typ[s] = pre + 1;
        return true;
    }
    for (auto x : adj2[s]) {
        if (typ[x] == 0) {
            ans |= dfs(x, pre + 1);
        } else if (typ[x] == pre + 2)
            ans = true;
    }
    if (ans) typ[s] = pre + 1;
    return ans;
}
void solve() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m >> v;
    vector<vector<int>> adj(m, vector<int>());
    adj2.assign(m, vector<int>());
    typ.assign(m, 0);
    queue<int> q;
    vector<int> tost(m, 0);
    for (int i = 0; i < v; i++) {
        int a, c;
        char b;
        cin >> a >> b >> c;
        if (b == '=') {
            adj[a - 1].PB(c - 1);
            adj[c - 1].PB(a - 1);
        }
        if (b == '<') {
            adj2[a - 1].PB(c - 1);
            tost[c - 1]++;
        }
        if (b == '>') {
            adj2[c - 1].PB(a - 1);
            tost[a - 1]++;
        }
    }
    for (int i = 0; i < m; i++) {
        if (tost[i] == 0) dfs(i, 0);
    }
    vector<bool> vis(m, false);
    for (int i = 0; i < m; i++) {
        if (typ[i] != 0) {
            q.push(i);
            vis[i] = true;
        }
    }
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (auto x : adj[u]) {
            if (vis[x]) continue;
            typ[x] = typ[u];
            vis[x] = true;
            q.push(x);
        }
    }
    for (int i = 0; i < m; i++) {
        if (typ[i] == 0)
            cout << '?' << endl;
        else
            cout << 'K' << typ[i] << endl;
    }
}
int32_t main() {
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message

kovanice.cpp:7: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    7 | #pragma optimize("AhmetEmreGurdal a.k.a. AEG")
      |
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 274 ms 17696 KB Output is correct
2 Correct 254 ms 17876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2037 ms 1880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2051 ms 28772 KB Time limit exceeded
2 Halted 0 ms 0 KB -