Submission #846365

# Submission time Handle Problem Language Result Execution time Memory
846365 2023-09-07T14:03:43 Z vjudge1 KOVANICE (COI15_kovanice) C++17
50 / 100
590 ms 41952 KB
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

vector<pair<int,int>>v[300005];
vector<int>v3;
int mn,mx,vis[300005],ans[300005];

void dfs(int node,int x){
	vis[node]=1;
	ans[node]=x;
	mn=min(mn,x);
	mx=max(mx,x);
	v3.pb(node);
	for(auto i:v[node]){
		if(vis[i.ff])continue;
		dfs(i.ff,x+i.ss);
	}
	return;
}

int32_t main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++)ans[i]=-1;
	vector<pair<int,int>>v2;
	for(int i=0;i<k;i++){
		string s;
		cin>>s;
		int a=0,b=0;
		string s2,s3;
		int ind=0;
		while(s[ind]!='<' && s[ind]!='='){
			s2+=s[ind];
			ind++;
		}
		int temp=ind;
		ind++;
		while(ind<s.size()){
			s3+=s[ind];
			ind++;
		}
		a=stoi(s2);
		b=stoi(s3);
		if(s[temp]=='='){
			v[a].pb({b,0});
			v[b].pb({a,0});
		}
		else{
			v[a].pb({b,1});
			v[b].pb({a,-1});
			v2.pb({a,0});
			v2.pb({b,1});
		}
	}
	for(auto i:v2){
		if(vis[i.ff])continue;
		v3.clear();
		mn=1e15,mx=-1e15;
		dfs(i.ff,0);
		if(mx-mn+1==n){
			for(auto i:v3){
				ans[i]-=mn;
			}
		}
	}
	for(int i=1;i<=m;i++){
		if(ans[i]==-1)cout<<"?"<<endl;
		else cout<<"K"<<ans[i]+1<<endl;
	}
}

Compilation message

kovanice.cpp: In function 'int32_t main()':
kovanice.cpp:46:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   while(ind<s.size()){
      |         ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8028 KB Output is correct
2 Correct 4 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 296 ms 19216 KB Output is correct
2 Correct 289 ms 19420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 17096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 590 ms 41952 KB Output isn't correct
2 Halted 0 ms 0 KB -