Submission #419864

# Submission time Handle Problem Language Result Execution time Memory
419864 2021-06-07T14:44:12 Z keta_tsimakuridze Ili (COI17_ili) C++14
0 / 100
1 ms 332 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=2e5+5,mod=1e9+7;
int t,fix[2][N],n,m;
pair<int,int> ind1[N],ind2[N];
char a[2][N],s[N],c[N],ans[N];
void dfs(int u,int t){
	a[t][u] = '0';
	if(!t) return;
	fix[t][u] = 1;
	dfs(ind1[u].f,ind1[u].s);
	dfs(ind2[u].f,ind2[u].s);
}
int get(string s){
	int cur = 0;
	for(int i=1;i<s.size();i++){
		cur=cur*10+s[i]-'0';
	}
	return cur;
}
main(){
	cin>>n>>m;
	for(int j=1;j<=n;j++) {
		a[0][j] = '?';
	}
	for(int i=1;i<=m;i++){
		cin>>a[1][i];
	} 	
	for(int i=1;i<=m;i++){
		string s1,s2;
		cin>>s1>>s2;
		if(s1[0]=='x') ind1[i]={get(s1),0};
		else  ind1[i]={get(s1),1};
		if(s2[0]=='x') ind2[i]={get(s2),0};
		else  ind2[i]={get(s2),1};
	}
	for(int i=m;i>=1;i--){
		if(a[1][i]=='0' && !fix[1][i]) dfs(i,1); 
	} 	

	for(int i=1;i<=m;i++) {
		if(a[ind1[i].s][ind1[i].f]=='1' || a[ind2[i].s][ind2[i].f]=='1') a[1][i] = '1';
		
	}
	for(int i=1;i<=m;i++) {
		s[i] = a[1][i];  
		if(a[1][i]=='?') a[1][i] = '1';
	} 
	for(int i=1;i<=n;i++) {
		c[i] = a[0][i];
		if(a[0][i]=='?') a[0][i] = '1';
	}
	for(int i=1;i<=m;i++){
		if(s[i]=='?') {
			dfs(i,1);
			ans[i] = '?';
			int F = 0;
			for(int j=1;j<=m;j++) {
				if(a[ind1[j].s][ind1[j].f]=='1' || a[ind2[j].s][ind2[j].f]=='1') a[1][j] = '1';
				else a[1][j] = '0';
				if(a[1][j] == '0' && s[j] == '1') F=1;
			}
			if(F) ans[i] = '1';
		}
		else ans[i] = s[i];
		for(int j=1;j<=m;j++){
			a[1][j] = s[j];
			if(a[1][j] == '?') a[1][j] = '1';
		}
		for(int j=1;j<=m;j++){
			a[0][j] = c[j];
			if(a[0][j]=='?') a[0][j] = '1';
		}
	}
	for(int i=1;i<=m;i++) cout<<ans[i];
}

Compilation message

ili.cpp: In function 'long long int get(std::string)':
ili.cpp:19:15: 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]
   19 |  for(int i=1;i<s.size();i++){
      |              ~^~~~~~~~~
ili.cpp: At global scope:
ili.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -