Submission #145232

# Submission time Handle Problem Language Result Execution time Memory
145232 2019-08-19T11:02:04 Z Fasho Zamjena (COCI18_zamjena) C++14
70 / 70
199 ms 13584 KB
#include <bits/stdc++.h>
#define N 50005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("kmp.in","r",stdin);freopen ("kmp.out","w",stdout);
#define mod 1000000009
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
#define INF 1000000000005

#define close(x) if(x) return cout<<"DA",0; return cout<<"NE",0;
using namespace std;

ll n,m,ar[N],sum,mark[N],res,flag;

vector<string> ans;

vector<int> v[N];

string s[3][N];

map<string,ll> mp;


void f(int ind)
{
	if(mark[ind])
		return;
	mark[ind]++;
	// cout<<ind<<sp;
	if(ar[ind])
	{
		if(res && res!=ar[ind])
		{
			// cout<<res<<":HELLO:"<<ind<<sp;
			flag=1;
		}
		res=ar[ind];
	}
	for(int i=0;i<v[ind].size();i++)
	{
		ll x=v[ind][i];
		if(!mark[x])
			f(x);
	}


}


void num(int ind)
{
	m=ans[ind].size();
	ll top=0;
	fo(i,0,m-1)
	{
		top*=10;
		top+=(ans[ind][i]-'0');
	}
	ar[ind]=top;
}


int main()
{
	fast;
	cin>>n;
	ll q=1;
	ans.pb("-1");

	fo(i,1,n)
	{
		cin>>s[1][i];
		if(!mp[s[1][i]])
			mp[s[1][i]]=q,q++,ans.pb(s[1][i]);
	}

	fo(i,1,n)
	{
		cin>>s[2][i];
		if(!mp[s[2][i]])
			mp[s[2][i]]=q,q++,ans.pb(s[2][i]);
	}


	for(int i=1;i<=n;i++)
	{
		v[mp[s[1][i]]].pb(mp[s[2][i]]);
		v[mp[s[2][i]]].pb(mp[s[1][i]]);
	}

	for(int i=0;i<ans.size();i++)
	{
		if(ans[i][0]>='0' && ans[i][0]<='9')
			num(i);
	}

	// cout<<endl;
	// for(int i=1;i<ans.size();i++)
	// {
		// cout<<ans[i]<<sp;


		// cout<<ans[i]<<endl;
		// for(int j=0;j<v[i].size();j++)
		// 	cout<<v[i][j]<<sp;
		// cout<<endl<<endl;
	// }
	// cout<<endl<<endl;

	// cout<<flag<<endl<<endl;
	for(int i=1;i<ans.size();i++)
	{

		if(mark[i])
			continue;
		res=0;
		// cout<<i<<endl;
		f(i);
		// cout<<flag<<endl<<endl;
		if(flag)
		{
			close(0);		
		}
		// cout<<endl<<endl;
	}
	close(1);

}

/*     cd onedrive\desktop\kod
cls


*/

Compilation message

zamjena.cpp: In function 'void f(int)':
zamjena.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v[ind].size();i++)
              ~^~~~~~~~~~~~~~
zamjena.cpp: In function 'int main()':
zamjena.cpp:101:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++)
              ~^~~~~~~~~~~
zamjena.cpp:121:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<ans.size();i++)
              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6264 KB Output is correct
2 Correct 9 ms 6136 KB Output is correct
3 Correct 9 ms 6264 KB Output is correct
4 Correct 7 ms 6136 KB Output is correct
5 Correct 8 ms 6264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6140 KB Output is correct
2 Correct 7 ms 6264 KB Output is correct
3 Correct 8 ms 6264 KB Output is correct
4 Correct 7 ms 6264 KB Output is correct
5 Correct 7 ms 6268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6264 KB Output is correct
2 Correct 8 ms 6240 KB Output is correct
3 Correct 9 ms 6264 KB Output is correct
4 Correct 7 ms 6264 KB Output is correct
5 Correct 7 ms 6236 KB Output is correct
6 Correct 7 ms 6136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6392 KB Output is correct
2 Correct 9 ms 6264 KB Output is correct
3 Correct 13 ms 6520 KB Output is correct
4 Correct 14 ms 6648 KB Output is correct
5 Correct 14 ms 6776 KB Output is correct
6 Correct 13 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 7284 KB Output is correct
2 Correct 58 ms 8580 KB Output is correct
3 Correct 101 ms 10288 KB Output is correct
4 Correct 127 ms 10800 KB Output is correct
5 Correct 199 ms 13584 KB Output is correct
6 Correct 134 ms 10216 KB Output is correct