Submission #846210

# Submission time Handle Problem Language Result Execution time Memory
846210 2023-09-07T12:30:41 Z vjudge1 KOVANICE (COI15_kovanice) C++
0 / 100
2000 ms 36356 KB
#include <bits/stdc++.h>
using namespace std;
#pragma optimize "DostSeferoğlu"
#pragma GCC optimize("unroll-loops,Ofast")
#pragma GCC target("avx2,tune=native")
#define int long long
#define pii pair<int,int>
#define bg begin
#define vi vector<int>
#define endl '\n'
#define vvi vector<vi> 
#define vp vector<pii>
#define sp << " " << 
#define ff first
#define ss second
#define brake {cout << "OK\n";return;}
#define debug(x) {cout << #x << ": "; for (auto it : x) cout << it << " ";cout << endl;}
#define FF(xxx,sss,yyy) for (int xxx=sss;xxx<=yyy;++xxx)
#define F(xx,yy) for (int xx=1;xx<=yy;++xx)
#define pb push_back 
const int inf = 1e18;
const int MOD = 998244353;   
const int N = 3e5+1;


vi dad(N),edges[N],inc[N],dp(N,-1),done(N,0),type(N,-1);

int find(int x) {
    if (x == dad[x])  return x;
    return dad[x] = find(dad[x]);
}
void unite(int x,int y) {
    dad[find(x)] = find(y);
}


int dfs(int node) {
    if (dp[node] != -1) return dp[node];
    int ans = 0;
    for (auto nb : edges[node]) {
        ans = max(ans,dfs(nb)+1);
    }
    return dp[node] = ans;
}


void yupee(int node,int ty) {
    type[node] = ty;
    for (auto nb : edges[node]) {
        if (dp[nb] == dp[node]-1) {
            yupee(nb,ty+1);
        }
    }
}

void solve() {
    int n,m,k;
    cin >> n >> m >> k;
    F(i,m) dad[i] = i;
    dad[0]=0;
    vp sms;
    while (k--) {
        string s;
        cin >> s;
        string n1,n2;
        int seeneq = 0,seensm=0,seenbg=0;
        for (auto c : s) {
            if (c == '=') {
                seeneq = 1;
                continue;
            }
            if (c == '<') {
                seensm = 1;
                continue;
            }
            if (c == '>') {
                seenbg = 1;
                continue;
            }
            if (seeneq || seenbg || seensm) {
                n2+=c;
            }else n1+=c;
        }
        int x = stoi(n1);
        int y = stoi(n2);
        if (seeneq) unite(x,y);
        else if (seensm) sms.pb({x,y});
        else sms.pb({y,x});
    }
    for (auto it : sms) {
        edges[find(it.ff)].pb(find(it.ss));
        inc[find(it.ss)].pb(find(it.ff));
    }
    vi vis(n+1,0);
    for (int i=1;i<=n;i++) dfs(find(i));
    for (int i=1;i<=n;i++) {
        if (!done[find(i)] && dp[find(i)] == n-1) {
            yupee(find(i),1);
        }
    }
    for (int i=1;i<=m;i++) {
        if (type[find(i)]!=-1) {
            cout << "K" << type[find(i)] << endl;
        }
        else {
            cout << "?\n";
        }
    }
}                 






signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef Local
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);  
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}

Compilation message

kovanice.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize "DostSeferoğlu"
      |
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 27856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 27336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2028 ms 36356 KB Time limit exceeded
2 Halted 0 ms 0 KB -