제출 #719850

#제출 시각아이디문제언어결과실행 시간메모리
719850jcelinDijamant (COI16_dijament)C++14
100 / 100
231 ms4056 KiB
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define msi multiset<int>
#define si set<int>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = mod;
const ll INF = 1e18;
const int logo = 20;
const int MAXN = 1e3 + 7;
const int off = 1 << logo;
const int trsz = off << 1;

int n, nod = 0;
map<string, int> id;
bitset<MAXN> gph[MAXN], rv[MAXN], prec[MAXN], emp, ch;

bool check(){
	FOR(i, 1, nod + 1){
		if(!emp[i]) continue;
		ch = (~gph[i] & prec[i]) & emp;
		if(ch.count()) return 1;
	}
	return 0;
}
void solve(){
	cin >> n;
	REP(i, n){
		string cur, e;
		cin >> cur >> e;
		if(id[cur]){
			while(1){
				cin >> e;
				if(e == ";") break;	
			}
			cout << "greska\n";
			continue;
		}
		
		emp.reset();
		int fl = 1;
		while(1){
			cin >> e;
			if(e == ";") break;
			fl = min(fl, id[e]);
			emp[id[e]] = 1;
		}
		
		if(fl == 0 or check()){
			cout << "greska\n";
			continue;
		}
		
		id[cur] = ++nod;
		REP(i, nod) if(emp[i]) emp |= gph[i];
		REP(i, nod) if(emp[i]) prec[nod] |= rv[i];
		REP(i, nod) if(emp[i]) rv[i][nod] = 1; 
		gph[nod] = emp;
		cout << "ok\n";
	}
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--)solve();
	return 0;
}




#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...