Submission #782390

# Submission time Handle Problem Language Result Execution time Memory
782390 2023-07-13T22:58:54 Z MasterTaster Ili (COI17_ili) C++14
100 / 100
2075 ms 3260 KB
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 20010

using namespace std;

int n, m, ress[MAXN], cnt[MAXN];
bool bio[MAXN], pombio[MAXN], dal0[MAXN];
vector<int> g[2][MAXN], guk[MAXN];
queue<int> q;

void dfs(int t, int u)
{
	bio[u]=true;
	for (auto v:g[t][u]) if (!bio[v]) dfs(t, v);
}

int main(){
	cin>>n>>m;
	string s; cin>>s;

	for (int i=0; i<n+m; i++) ress[i]=-1;
	for (int i=0; i<m; i++) if (s[i]!='?') { ress[i+n]=s[i]-'0';  if (ress[i+n]==0) { q.push(i+n); bio[i+n]=true; } }

	for (int i=0; i<m; i++)
	{
		string s1, s2; cin>>s1>>s2;
		int a, b;
		if (s1[0]=='x')
		{
			string pom=s1.substr(1, s1.size()-1);
			a=stoi(pom)-1;
		}
		else
		{
			string pom=s1.substr(1, s1.size()-1);
			a=stoi(pom)-1+n;
		}

		if (s2[0]=='x')
		{
			string pom=s2.substr(1, s2.size()-1);
			b=stoi(pom)-1;
		}
		else
		{
			string pom=s2.substr(1, s2.size()-1);
			b=stoi(pom)-1+n;
		}

		g[0][a].pb(i+n); g[1][i+n].pb(a);
		g[0][b].pb(i+n); g[1][i+n].pb(b);
		guk[a].pb(i+n); guk[i+n].pb(a);
		guk[b].pb(i+n); guk[i+n].pb(b);
		//cout<<a<<" "<<i+n<<endl;
		//cout<<b<<" "<<i+n<<endl;
	}

	while (!q.empty())
	{
		int u=q.front();
		q.pop();
		//cout<<u<<"UU:"<<endl;
		for (auto v:guk[u])
		{
			if (v>u) { cnt[v]++; }
			if (((v<u || cnt[v]>=2 || v<n) && !bio[v])) { bio[v]=true; ress[v]=0; q.push(v); }
		}
	}

	for (int i=0; i<n; i++) if (ress[i]==-1) ress[i]=1;

	for (int i=0; i<m; i++) if (ress[i+n]==-1) dal0[i+n]=1;

	for (int i=0; i<n+m; i++) bio[i]=false;

	for (int i=0; i<m; i++)
	{
		if (ress[i+n]!=-1) continue;

		for (int j=0; j<n+m; j++) bio[j]=false;
		dfs(1, i+n);
		//cout<<i<<":"<<endl;
		for (int j=0; j<n+m; j++) pombio[j]=0;
		for (int j=0; j<n; j++)
		{
			if (!bio[j] && ress[j]==1)
			{
				q.push(j); pombio[j]=1;//cout<<j<<" ";
			}
		}
		//cout<<endl;
		for (int j=0; j<n+m; j++) bio[j]=pombio[j];
		
		while (!q.empty())
		{
			int u=q.front();
			q.pop();
			for (auto v:g[0][u])
			{
				if (!bio[v]) { bio[v]=true; q.push(v); }
			}
		}

		for (int j=0; j<m; j++) if (ress[j+n]==1 && !bio[j+n]) dal0[i+n]=0;
	}
//cout<<"EE"<<endl;

	for (int i=0; i<m; i++) if (ress[i+n]==-1) { if (dal0[i+n]) cout<<'?'; else cout<<1; } else cout<<ress[i+n];



	//for (int i=0; i<n+m; i++) if (bio[i]) cout<<i<<" ";
	//cout<<endl;

	/*for (int i=0; i<n+m; i++) if (ress[i]==1) q.push(i);
	while (!q.empty())
	{
		int u=q.front();
		q.pop();
		for (auto v:g[u])
		{	
			if (v>u) { ress[v]=1; if (!bio[v]) { bio[v]=true; q.push(v); } }
			else
			{
				int veci=-1, ksor=0;
				for (auto x:g[u]) { ksor=ksor^x; veci=max(veci, x); }

				int w;
				if (g[u].size()==3) w=(ksor^veci)^v;
				else w=ksor^v;
				//{v, w} --(or)--> u
				//cout<<v<<" | "<<w<<" ---> "<<u<<endl;
				if (ress[w]==0 && !bio[v]) { ress[v]=1; bio[v]=true; q.push(v); }
			}
		}
	}

	//for (int i=0; i<n+m; i++) cout<<ress[i]<<" ";
	//cout<<endl;
	for (int i=0; i<m; i++) if (ress[i+n]==-1) cout<<'?'; else cout<<ress[i+n];*/


	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1616 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1616 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1620 KB Output is correct
8 Correct 3 ms 1748 KB Output is correct
9 Correct 2 ms 1748 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 3 ms 1876 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
13 Correct 2 ms 1748 KB Output is correct
14 Correct 4 ms 1672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1616 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1620 KB Output is correct
8 Correct 3 ms 1748 KB Output is correct
9 Correct 2 ms 1748 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 3 ms 1876 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
13 Correct 2 ms 1748 KB Output is correct
14 Correct 4 ms 1672 KB Output is correct
15 Correct 320 ms 2368 KB Output is correct
16 Correct 589 ms 2516 KB Output is correct
17 Correct 414 ms 2644 KB Output is correct
18 Correct 1877 ms 2900 KB Output is correct
19 Correct 466 ms 2644 KB Output is correct
20 Correct 1392 ms 3148 KB Output is correct
21 Correct 2075 ms 3196 KB Output is correct
22 Correct 424 ms 3216 KB Output is correct
23 Correct 440 ms 3260 KB Output is correct
24 Correct 425 ms 3216 KB Output is correct
25 Correct 367 ms 2852 KB Output is correct
26 Correct 359 ms 2824 KB Output is correct
27 Correct 374 ms 2772 KB Output is correct
28 Correct 308 ms 2788 KB Output is correct
29 Correct 343 ms 2816 KB Output is correct
30 Correct 348 ms 2820 KB Output is correct
31 Correct 234 ms 2884 KB Output is correct
32 Correct 322 ms 2900 KB Output is correct