Submission #204123

# Submission time Handle Problem Language Result Execution time Memory
204123 2020-02-24T13:22:28 Z pxh612 Coin Collecting (JOI19_ho_t4) C++14
100 / 100
68 ms 7544 KB
#include<bits/stdc++.h>
#define int ll
//{ PXH612
using namespace std;
#define ll long long
#define db double
#define pp pair<int,int>
#define x first
#define y second

#define false(x) if(!(x))
template<typename A,typename B>bool Min(A &a,B b){if(a<=b) return 0;a=b;return 1;}
template<typename A,typename B>bool Max(A &a,B b){if(a>=b) return 0;a=b;return 1;}
#define in ({ll x=0;int o=0,c=char(),t=0;for(;!isdigit(c)&&t<1000;c=getchar(),t++) o=c=='-';for(;isdigit(c);c=getchar()) x=x*10+c-'0';o?-x:x;})
#define inchar ({char c=getchar();while(c==' '||c=='\n') c=getchar();c;})

#define FOR(i,a,b) for(int i=a,ENDFOR=b;i<=ENDFOR;i++)
#define ROF(i,a,b) for(int i=b,ENDFOR=a;ENDFOR<=i;i--)
#define RR(x,a,b) {cout<<#x<<": ";FOR(_,a,b) cout<<x[_]<<" ";cout<<"\n";}
#define rr(x) " "<<#x<<'='<<(x)<<" "

#define VEC(i,a) for(auto&i:a)
#define pb push_back
#define vn(a) (int)a.size()-1

#define bit(x,i) ((x>>(i-1))&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
#define mu(x) (1ll<<x)
#define bitnum(x) __builtin_popcountll(x)

#define segg(a,b) (abs(a-b)+1)
#define midd(a,b) (a+(b-(a))/2)
#define mems(x,a) memset(x,a,sizeof x)
#define open(a) freopen(a,"r",stdin)
#define shut(b) freopen(b,"w",stdout)
//}/////////////////////////////////////////////////////}

const int N=1e5+5;
int n;
ll res=0;
int f[N][5];
int d[N][5];

int sum[5];
main()
{
  //  open("coin.inp");
  //  shut("coin.out");
    n=in;
    FOR(i,1,n*2)
    {
        int x=in,y=in;
        int X=x,Y=y;
        Max(X,1);Min(X,n);
        Max(Y,1);Min(Y,2);
        res+=abs(x-X)+abs(y-Y);
        f[X][Y]++;
    }


    FOR(i,1,n)
    {
      //  cout<<"=================" rr(i) "\n";
        FOR(ud,1,2) res+=abs(sum[ud]);
        FOR(ud,1,2) sum[ud]+=f[i][ud]-1;
        while(sum[1]>0&&sum[2]<0)
        {
            sum[1]--;
            sum[2]++;
            res++;
        }
        while(sum[1]<0&&sum[2]>0)
        {
            sum[1]++;
            sum[2]--;
            res++;
        }
        //assert(sum[1]<0);
       // assert(sum[1]<0);
    }
    cout<<res;
}

Compilation message

joi2019_ho_t4.cpp:46:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 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 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 368 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 380 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
# 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 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 368 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 380 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 376 KB Output is correct
37 Correct 6 ms 436 KB Output is correct
38 Correct 5 ms 380 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 6 ms 376 KB Output is correct
41 Correct 5 ms 376 KB Output is correct
42 Correct 5 ms 376 KB Output is correct
43 Correct 5 ms 376 KB Output is correct
44 Correct 5 ms 376 KB Output is correct
45 Correct 6 ms 376 KB Output is correct
46 Correct 6 ms 376 KB Output is correct
47 Correct 5 ms 376 KB Output is correct
48 Correct 5 ms 376 KB Output is correct
49 Correct 5 ms 376 KB Output is correct
50 Correct 5 ms 376 KB Output is correct
51 Correct 6 ms 376 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 5 ms 376 KB Output is correct
54 Correct 5 ms 376 KB Output is correct
55 Correct 5 ms 376 KB Output is correct
56 Correct 5 ms 376 KB Output is correct
57 Correct 5 ms 248 KB Output is correct
58 Correct 5 ms 380 KB Output is correct
59 Correct 5 ms 376 KB Output is correct
60 Correct 5 ms 376 KB Output is correct
61 Correct 5 ms 376 KB Output is correct
62 Correct 5 ms 376 KB Output is correct
63 Correct 5 ms 376 KB Output is correct
64 Correct 5 ms 376 KB Output is correct
# 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 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 368 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 380 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 376 KB Output is correct
37 Correct 6 ms 436 KB Output is correct
38 Correct 5 ms 380 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 6 ms 376 KB Output is correct
41 Correct 5 ms 376 KB Output is correct
42 Correct 5 ms 376 KB Output is correct
43 Correct 5 ms 376 KB Output is correct
44 Correct 5 ms 376 KB Output is correct
45 Correct 6 ms 376 KB Output is correct
46 Correct 6 ms 376 KB Output is correct
47 Correct 5 ms 376 KB Output is correct
48 Correct 5 ms 376 KB Output is correct
49 Correct 5 ms 376 KB Output is correct
50 Correct 5 ms 376 KB Output is correct
51 Correct 6 ms 376 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 5 ms 376 KB Output is correct
54 Correct 5 ms 376 KB Output is correct
55 Correct 5 ms 376 KB Output is correct
56 Correct 5 ms 376 KB Output is correct
57 Correct 5 ms 248 KB Output is correct
58 Correct 5 ms 380 KB Output is correct
59 Correct 5 ms 376 KB Output is correct
60 Correct 5 ms 376 KB Output is correct
61 Correct 5 ms 376 KB Output is correct
62 Correct 5 ms 376 KB Output is correct
63 Correct 5 ms 376 KB Output is correct
64 Correct 5 ms 376 KB Output is correct
65 Correct 42 ms 5752 KB Output is correct
66 Correct 68 ms 4984 KB Output is correct
67 Correct 55 ms 7416 KB Output is correct
68 Correct 59 ms 7544 KB Output is correct
69 Correct 54 ms 7416 KB Output is correct
70 Correct 58 ms 7392 KB Output is correct
71 Correct 61 ms 7544 KB Output is correct
72 Correct 47 ms 3576 KB Output is correct
73 Correct 47 ms 3576 KB Output is correct
74 Correct 50 ms 3576 KB Output is correct
75 Correct 47 ms 3448 KB Output is correct
76 Correct 48 ms 3576 KB Output is correct
77 Correct 47 ms 3448 KB Output is correct
78 Correct 49 ms 3576 KB Output is correct
79 Correct 47 ms 3576 KB Output is correct
80 Correct 51 ms 3568 KB Output is correct
81 Correct 47 ms 3580 KB Output is correct
82 Correct 47 ms 3576 KB Output is correct
83 Correct 48 ms 3704 KB Output is correct
84 Correct 49 ms 3880 KB Output is correct
85 Correct 47 ms 3832 KB Output is correct
86 Correct 51 ms 6116 KB Output is correct
87 Correct 49 ms 6008 KB Output is correct
88 Correct 49 ms 7416 KB Output is correct
89 Correct 52 ms 7520 KB Output is correct
90 Correct 55 ms 7416 KB Output is correct
91 Correct 55 ms 7416 KB Output is correct
92 Correct 60 ms 7544 KB Output is correct
93 Correct 59 ms 7544 KB Output is correct
94 Correct 55 ms 7288 KB Output is correct
95 Correct 54 ms 7288 KB Output is correct
96 Correct 56 ms 6264 KB Output is correct
97 Correct 51 ms 6136 KB Output is correct
98 Correct 55 ms 5880 KB Output is correct
99 Correct 49 ms 5368 KB Output is correct
100 Correct 51 ms 5368 KB Output is correct
101 Correct 52 ms 5960 KB Output is correct
102 Correct 52 ms 5496 KB Output is correct
103 Correct 51 ms 5240 KB Output is correct