Submission #99202

# Submission time Handle Problem Language Result Execution time Memory
99202 2019-03-01T16:11:23 Z dsg213 Dijamant (COI16_dijament) C++14
100 / 100
478 ms 4744 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
const int mod=1000000007,mxn=1010;
vector<int> kra[mxn];
int zal[mxn];
map<string,int> mapp;
int dp[mxn];
int dod[mxn];
vector<int> use;
int spr(int kt){
	use.clear();
	for(int i=kt-1;i>0;i--){
		if(dod[i]==1 && dp[i]==0){
			use.pb(i);
			dp[i]=1;
		}
		if(!dp[i]){
			continue;
		}
		for(int j=0;j<kra[i].size();j++){
			dp[kra[i][j]]++;
			if(dp[kra[i][j]]==2){
				return 0;
			}
		}
	}
	return 1;
}
void rob(int kt){
	string s;
	cin >>s;
	string s2;
	cin >>s2;
	vector<string> vs; 
	while(1){
		cin >>s2;
		if(s2==";"){
			break;
		}
		vs.pb(s2);
	}
	if(mapp[s]){
		cout <<"greska\n";
		return;
	}
	vector<int> vec;
	for(int i=0;i<=kt;i++){
		dp[i]=0;
		dod[i]=0;
	}
	for(int i=0;i<vs.size();i++){
		if(!mapp[vs[i]]){
			cout <<"greska\n";
			return;
		}
		vec.pb(mapp[vs[i]]);
		//cout <<vec[i] <<" ";
		dod[vec[i]]=1;
	}
	int x=spr(kt);
	if(x==0){
		cout <<"greska\n";
		return;
	}
	mapp[s]=kt;
	cout <<"ok\n";
	//cout <<"po " <<vs.size() <<endl;
	for(int i=0;i<use.size();i++){
		kra[kt].pb(use[i]);
	}
}
int main(){
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);
	
	int n;
	cin >>n;
	for(int i=1;i<=n;i++){
		rob(i);
		/*for(int j=1;j<=i;j++){
			cout <<j <<": ";
			for(int x=0;x<kra[j].size();x++){
				cout <<kra[j][x]<<" ";
			}
			cout <<"\n";
		}*/
	}
}

Compilation message

dijament.cpp: In function 'int spr(int)':
dijament.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<kra[i].size();j++){
               ~^~~~~~~~~~~~~~
dijament.cpp: In function 'void rob(int)':
dijament.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<vs.size();i++){
              ~^~~~~~~~~~
dijament.cpp:78:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<use.size();i++){
              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 9 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 9 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 432 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
16 Correct 6 ms 396 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 401 ms 904 KB Output is correct
2 Correct 478 ms 4724 KB Output is correct
3 Correct 262 ms 4744 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 16 ms 640 KB Output is correct
7 Correct 28 ms 640 KB Output is correct
8 Correct 48 ms 820 KB Output is correct
9 Correct 46 ms 888 KB Output is correct
10 Correct 15 ms 640 KB Output is correct
11 Correct 16 ms 640 KB Output is correct
12 Correct 377 ms 3864 KB Output is correct