답안 #204127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204127 2020-02-24T13:29:38 Z tduong0806 Coin Collecting (JOI19_ho_t4) C++14
100 / 100
65 ms 4728 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int long long
int hmt() {int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';if(n) x=-x;return x;}
#define in hmt()
#define ins ({string x;char c=getchar();for(;c==' '||c=='\n';c=getchar());for(;c!=' '&&c!='\n';c=getchar()) x+=c;x;})
#define forinc(i,a,b) for(int i=a,_b=b;i<=_b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forb(i,BS) for(int i=BS._Find_first();i< BS.size();i = BS._Find_next(i))
#define forv(a,b) for(auto &a:b)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define onbit(x,i) (x|(1<<(i-1)))
#define offbit(x,i) (x&~(1<<(i-1)))
const int N=2e5+10;
int n,f[N][3],s[N],ans;
pii a[N];
void add(int x,int y)
{
    if(x>n) ans+=x-n,x=n;
    if(x<1) ans+=1-x,x=1;
    if(y>2) ans+=y-2,y=2;
    if(y<1) ans+=1-y,y=1;
    f[x][y]++;
}
main()
{
    //freopen("JOI2019.inp","r",stdin);
    n=in;
    forinc(i,1,2*n)
    {
        int x=in,y=in;
        add(x,y);
    }
    int s1=0,s2=0;
    forinc(i,1,n)
    {
        s1+=max(0ll,f[i][1]-1);
        s2+=max(0ll,f[i][2]-1);
        if(!f[i][1])
        {
            if(s1) s1--;
            else if(s2>1||(s2==1&&f[i][2])) ans++,s2--;
            else s1--;
        }
        if(!f[i][2])
        {
            if(s2) s2--;
            else if(s1>0) ans++,s1--;
            else s2--;
        }
        if(s1<0&&s2>0)
        {
            ans+=min(abs(s1),abs(s2));
            if(abs(s1)>abs(s2)) s1+=s2,s2=0;
            else s2+=s1,s1=0;
        }
        if(s1>0&&s2<0)
        {
            ans+=min(abs(s1),abs(s2));
            if(abs(s1)>abs(s2)) s1+=s2,s2=0;
            else s2+=s1,s1=0;
        }
        ans+=abs(s1)+abs(s2);
    }
    cout<<ans<<"\n";
}

Compilation message

joi2019_ho_t4.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 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 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 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 504 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 376 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 248 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 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 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 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 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 504 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 376 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 248 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 508 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 6 ms 376 KB Output is correct
36 Correct 5 ms 380 KB Output is correct
37 Correct 5 ms 376 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 5 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 6 ms 376 KB Output is correct
44 Correct 5 ms 376 KB Output is correct
45 Correct 5 ms 376 KB Output is correct
46 Correct 5 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 5 ms 380 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 376 KB Output is correct
54 Correct 5 ms 376 KB Output is correct
55 Correct 6 ms 376 KB Output is correct
56 Correct 5 ms 376 KB Output is correct
57 Correct 5 ms 376 KB Output is correct
58 Correct 5 ms 376 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
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 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 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 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 504 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 376 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 248 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 508 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 6 ms 376 KB Output is correct
36 Correct 5 ms 380 KB Output is correct
37 Correct 5 ms 376 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 5 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 6 ms 376 KB Output is correct
44 Correct 5 ms 376 KB Output is correct
45 Correct 5 ms 376 KB Output is correct
46 Correct 5 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 5 ms 380 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 376 KB Output is correct
54 Correct 5 ms 376 KB Output is correct
55 Correct 6 ms 376 KB Output is correct
56 Correct 5 ms 376 KB Output is correct
57 Correct 5 ms 376 KB Output is correct
58 Correct 5 ms 376 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 39 ms 4264 KB Output is correct
66 Correct 65 ms 2300 KB Output is correct
67 Correct 52 ms 4600 KB Output is correct
68 Correct 59 ms 4728 KB Output is correct
69 Correct 53 ms 4600 KB Output is correct
70 Correct 55 ms 4604 KB Output is correct
71 Correct 52 ms 4600 KB Output is correct
72 Correct 49 ms 2288 KB Output is correct
73 Correct 49 ms 2296 KB Output is correct
74 Correct 51 ms 2296 KB Output is correct
75 Correct 49 ms 2296 KB Output is correct
76 Correct 49 ms 2296 KB Output is correct
77 Correct 49 ms 2296 KB Output is correct
78 Correct 49 ms 2296 KB Output is correct
79 Correct 49 ms 2296 KB Output is correct
80 Correct 50 ms 2428 KB Output is correct
81 Correct 50 ms 2424 KB Output is correct
82 Correct 49 ms 2296 KB Output is correct
83 Correct 49 ms 2296 KB Output is correct
84 Correct 49 ms 2680 KB Output is correct
85 Correct 49 ms 2680 KB Output is correct
86 Correct 49 ms 4216 KB Output is correct
87 Correct 50 ms 4088 KB Output is correct
88 Correct 50 ms 4600 KB Output is correct
89 Correct 51 ms 4600 KB Output is correct
90 Correct 54 ms 4600 KB Output is correct
91 Correct 53 ms 4600 KB Output is correct
92 Correct 58 ms 4644 KB Output is correct
93 Correct 53 ms 4600 KB Output is correct
94 Correct 54 ms 4644 KB Output is correct
95 Correct 50 ms 4600 KB Output is correct
96 Correct 53 ms 3832 KB Output is correct
97 Correct 51 ms 3832 KB Output is correct
98 Correct 51 ms 3576 KB Output is correct
99 Correct 50 ms 3320 KB Output is correct
100 Correct 54 ms 3448 KB Output is correct
101 Correct 52 ms 3704 KB Output is correct
102 Correct 52 ms 3448 KB Output is correct
103 Correct 51 ms 3320 KB Output is correct