답안 #576925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576925 2022-06-13T20:18:02 Z Mounir KOVANICE (COI15_kovanice) C++14
60 / 100
705 ms 72740 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define pb push_back
#define pii pair<int, int>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define print(x) cout << #x << " est " << x << endl;
#define x first
#define y second
#define int long long
using namespace std;

const int N = 1e6;
int ens[N];
int getEns(int noeud){
      if (ens[noeud] != noeud)
            ens[noeud] = getEns(ens[noeud]);
      return ens[noeud];
}

vector<int> petits[N], gros[N];
int maxChemin[N];
vector<int> ordre;
bool vu[N];
bool isWin[N];

int dfs(int noeud){
      if (!vu[noeud]){
            vu[noeud] = true;
            for (int petit : petits[noeud])
                  chmax(maxChemin[noeud], dfs(petit));
            maxChemin[noeud]++;
            ordre.pb(noeud);
      }
      return maxChemin[noeud];
}

signed main(){ 
      int nTypes, nPieces, nMesures; cin >> nTypes >> nPieces >> nMesures;
      for (int i = 0; i < nPieces; ++i)
            ens[i] = i;
      vector<pii> aretes;
      for (int i = 0; i < nMesures; ++i){
            int first, second;
            char op; cin >> first >> op >> second;
            --first; --second;
            if (op == '=')
                  ens[getEns(first)] = getEns(second);
            else if (op == '<')
                  aretes.pb({second, first});
            else
                  aretes.pb({first, second});
           // cout << "salut" << endl;

      }

      for (pii arete : aretes){
            petits[getEns(arete.first)].pb(getEns(arete.second));
            gros[getEns(arete.second)].pb(getEns(arete.first));
      }

      for (int i = 0; i < nPieces; ++i){
            if (ens[i] != i) continue;
            isWin[i] = (dfs(i) == nTypes);
      }

      reverse(all(ordre));
      for (int cur : ordre)
            for (int apres : gros[cur])
                  isWin[cur] |= isWin[apres];


      for (int iPiece = 0; iPiece < nPieces; ++iPiece){
            int nod = getEns(iPiece);
            if (isWin[nod] || maxChemin[nod] > nTypes)
                  cout << "K" << min(nTypes, maxChemin[nod]) << endl;
            else
                  cout << "?" << endl;
      }
      return 0;   
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47316 KB Output is correct
2 Correct 28 ms 47316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 57764 KB Output is correct
2 Correct 353 ms 58016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 51608 KB Output is correct
2 Correct 72 ms 51812 KB Output is correct
3 Correct 73 ms 51784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 705 ms 72740 KB Output isn't correct
2 Halted 0 ms 0 KB -