Submission #145231

# Submission time Handle Problem Language Result Execution time Memory
145231 2019-08-19T10:51:55 Z TadijaSebez Coin Collecting (JOI19_ho_t4) C++11
0 / 100
2 ms 380 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=100050;
int cnt[N][3];
ll ans=0;
queue<int> c[2],g[2];
void Solve()
{
	if(c[0].empty() || g[0].empty()) ans+=g[0].size()+c[0].size();
	else ans+=g[1].size()+c[1].size();
	vector<int> A,B;
	for(int i=0;i<2;i++) while(c[i].size()) A.pb(c[i].front()),c[i].pop();
	for(int i=0;i<2;i++) while(g[i].size()) B.pb(g[i].front()),g[i].pop();
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	for(int i=0;i<A.size();i++) ans+=abs(A[i]-B[i]);
}
int main()
{
	int n,x,y;
	scanf("%i",&n);
	for(int i=1;i<=2*n;i++)
	{
		scanf("%i %i",&x,&y);
		if(x<1) ans+=1-x,x=1;
		if(x>n) ans+=x-n,x=n;
		if(y<1) ans+=1-y,y=1;
		if(y>2) ans+=y-2,y=2;
		cnt[x][y-1]++;
		//printf("X:%i Y:%i",x,y);
	}
	//printf("CNT:\n");
	for(int j=0;j<2;j++)
	{
		for(int i=1;i<=n;i++)
		{
			//printf("%i ",cnt[i][j]);
			for(int k=2;k<=cnt[i][j];k++) c[j].push(i);
			if(cnt[i][j]==0) g[j].push(i);
		}
		//printf("\n");
	}
	while(c[0].size() && c[1].size() && g[0].size() && g[1].size())
	{
		int c0=c[0].front();
		int c1=c[1].front();
		int q0=g[0].front();
		int q1=g[1].front();
		if(c0<=c1)
		{
			if(abs(c0-q0)+abs(c1-q1)<=abs(c0-q1)+abs(c1-q0)+2)
			{
				ans+=abs(c0-q0)+abs(c1-q1);
				c[0].pop();
				g[0].pop();
				c[1].pop();
				g[1].pop();
				//printf("%i 0 %i 0\n",c0,q0);
			}
			else
			{
				ans+=abs(c0-q1)+1;
				c[0].pop();
				g[1].pop();
				//printf("%i 0 %i 1\n",c0,q1);
			}
		}
		else
		{
			if(abs(c0-q0)+abs(c1-q1)<=abs(c0-q1)+abs(c1-q0)+2)
			{
				ans+=abs(c0-q0)+abs(c1-q1);
				c[0].pop();
				g[0].pop();
				c[1].pop();
				g[1].pop();
				//printf("%i 1 %i 1\n",c1,q1);
			}
			else
			{
				ans+=abs(c1-q0)+1;
				c[1].pop();
				g[0].pop();
				//printf("%i 1 %i 0\n",c1,q0);
			}
		}
		/*if(c0<c1)
		{
			if(q0<=q1)
			{
				ans+=abs(c0-q0);
				c[0].pop();
				q[0].pop();
			}
			else
			{
				if(q1<c0)
				{
					ans+=abs(c0-q1)+1;
					c[0].pop();
					q[1].pop();
				}
				else
				{
					if(c1<=q1)
					{
						ans+=abs(c0-q0)+abs(c1-q1);
						c[0].pop();
						c[1].pop();
						q[0].pop();
						q[1].pop();
					}
					else
					{

					}
				}
			}
		}
		else if(c1<c0)
		{

		}
		else
		{
			if(q0<=q1)
			{
				ans+=abs(c0-q0);
				c[0].pop();
				q[0].pop();
			}
			else
			{
				ans+=abs(c1-q1);
				c[1].pop();
				q[1].pop();
			}
		}*/
	}
	Solve();
	printf("%lld\n",ans);
	return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'void Solve()':
joi2019_ho_t4.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<A.size();i++) ans+=abs(A[i]-B[i]);
              ~^~~~~~~~~
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
joi2019_ho_t4.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&x,&y);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 312 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 312 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 312 KB Output isn't correct
8 Halted 0 ms 0 KB -