답안 #292148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292148 2020-09-06T12:50:12 Z YJU Coin Collecting (JOI19_ho_t4) C++14
100 / 100
67 ms 5928 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
typedef pair<ll,pair<ll,pair<ll,pll> > > TY;
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()

ll n,x,y,cnt[N][3],lst=1,ans;

pll to(pll A){
	if(A.X<1)ans+=abs(A.X-1),A.X=1;
	if(A.X>n)ans+=abs(A.X-n),A.X=n;
	if(A.Y>2)ans+=abs(A.Y-2),A.Y=2;
	if(A.Y<1)ans+=abs(A.Y-1),A.Y=1;
	return A;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP1(i,2*n){
		cin>>x>>y;
		pll nd=to(mp(x,y));
		++cnt[nd.X][nd.Y];
	}
	ll t1=0,t2=0;
	REP1(i,n){
		t1+=cnt[i][1]-1;
		t2+=cnt[i][2]-1;
		if(t1*t2<0){
			ll tmp=min(abs(t1),abs(t2));
			ans+=tmp;
			if(t1<0){
				t1+=tmp;t2-=tmp;
			}else{
				t1-=tmp;t2+=tmp;
			}
		}
		ans+=abs(t1)+abs(t2);
	}
	cout<<ans<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 456 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 2 ms 416 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 2 ms 412 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 456 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 2 ms 416 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 2 ms 412 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 40 ms 4216 KB Output is correct
66 Correct 64 ms 4988 KB Output is correct
67 Correct 60 ms 5880 KB Output is correct
68 Correct 58 ms 5920 KB Output is correct
69 Correct 57 ms 5800 KB Output is correct
70 Correct 59 ms 5880 KB Output is correct
71 Correct 56 ms 5880 KB Output is correct
72 Correct 46 ms 3584 KB Output is correct
73 Correct 52 ms 3580 KB Output is correct
74 Correct 49 ms 3584 KB Output is correct
75 Correct 52 ms 3460 KB Output is correct
76 Correct 50 ms 3576 KB Output is correct
77 Correct 47 ms 3448 KB Output is correct
78 Correct 48 ms 3576 KB Output is correct
79 Correct 48 ms 3704 KB Output is correct
80 Correct 50 ms 3576 KB Output is correct
81 Correct 47 ms 3596 KB Output is correct
82 Correct 47 ms 3580 KB Output is correct
83 Correct 51 ms 3620 KB Output is correct
84 Correct 53 ms 3952 KB Output is correct
85 Correct 47 ms 3832 KB Output is correct
86 Correct 63 ms 5416 KB Output is correct
87 Correct 60 ms 5368 KB Output is correct
88 Correct 56 ms 5880 KB Output is correct
89 Correct 67 ms 5880 KB Output is correct
90 Correct 63 ms 5880 KB Output is correct
91 Correct 66 ms 5792 KB Output is correct
92 Correct 56 ms 5928 KB Output is correct
93 Correct 56 ms 5880 KB Output is correct
94 Correct 58 ms 5752 KB Output is correct
95 Correct 60 ms 5880 KB Output is correct
96 Correct 57 ms 5240 KB Output is correct
97 Correct 52 ms 5112 KB Output is correct
98 Correct 51 ms 4960 KB Output is correct
99 Correct 56 ms 4636 KB Output is correct
100 Correct 51 ms 4696 KB Output is correct
101 Correct 51 ms 4984 KB Output is correct
102 Correct 59 ms 4752 KB Output is correct
103 Correct 49 ms 4600 KB Output is correct