Submission #203813

# Submission time Handle Problem Language Result Execution time Memory
203813 2020-02-22T09:02:09 Z kig9981 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
5 ms 376 KB
#include <bits/stdc++.h>
 
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
 
using namespace std;

vector<pair<int,int>> P;
multiset<int> S[2];
int X[100000][2];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N;
	long long ans=0;
	cin>>N;
	P.resize(2*N);
	for(auto &[x,y]: P) cin>>x>>y;
	sort(P.begin(),P.end());
	for(int i=0;i<N;i++) {
		ans+=abs(i+1LL-P[2*i].first)+abs(i+1LL-P[2*i+1].first)+abs(1LL-P[2*i].second)+abs(2LL-P[2*i+1].second);
		if(P[2*i].second>1) {
			auto it=S[0].lower_bound(min(i+1,P[2*i].first));
			if(it!=S[0].end()) {
				ans-=2;
				S[0].erase(it);
				continue;
			}
			S[1].insert(max(i+1,P[2*i].first));
		}
		if(P[2*i+1].second<2) {
			auto it=S[1].lower_bound(min(i+1,P[2*i+1].first));
			if(it!=S[1].end()) {
				ans-=2;
				S[1].erase(it);
				continue;
			}
			S[0].insert(max(i+1,P[2*i+1].first));
		}
	}
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Incorrect 5 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Incorrect 5 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Incorrect 5 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -