Submission #204140

# Submission time Handle Problem Language Result Execution time Memory
204140 2020-02-24T14:38:42 Z nubboiiiii Coin Collecting (JOI19_ho_t4) C++14
0 / 100
7 ms 2684 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(i,x) for(auto &i:x)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
    return l+rng()%(r-l+1);
}
#define in ({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';n?-x:x;})
#define pii pair<int,int>
#define fi first
#define se second
#define batbit(i,x) (x|(1ll<<i))
#define getbit(i,x) ((x>>i)&1)

const int mn=1e5+10;
int cnt[mn][3],n,kq;

main()
{
    //freopen("test.inp","r",stdin);

    memset(cnt,-1,sizeof cnt);
    cin >> n;
    forinc(i,1,2*n)
    {
        int x,y;
        cin >> x >> y;
        if(x>=1&&x<=n)
        {
            if(y<=1)
            {
                cnt[x][1]++;
                kq+=abs(1-y);
            }
            else
            {
                cnt[x][2]++;
                kq+=abs(y-2);
            }
        }
        else
        {
            if(x<1)
            {
                if(y<=1)
                {
                    cnt[1][1]++;
                    kq+=abs(1-y)+abs(1-x);
                }
                else
                {
                    cnt[1][2]++;
                    kq+=abs(y-2)+abs(1-x);
                }
            }
            else
            {
                if(y<=1)
                {
                    cnt[n][1]++;
                    kq+=abs(1-y)+abs(x-n);
                }
                else
                {
                    cnt[n][2]++;
                    kq+=abs(y-2)+abs(x-n);
                }
            }
        }
    }
    cnt[0][1]=cnt[0][2]=0;
    forinc(i,1,n)
    {
        forinc(j,1,2)
        {
            cnt[i][j]+=cnt[i-1][j];
            kq+=abs(cnt[i-1][j]);
        }
        if(cnt[i][1]*cnt[i][2]<0)
        {
            cnt[i][1]+=cnt[i][2];
            kq+=abs(cnt[i][2]);
            cnt[i][2]=0;
        }
    }
    cout << kq;
}



/*

    0 0 -1 kq=0;
    1 0 0

    0 0 -1  kq=1
    1 1 0

    0 0 -1  kq=2;
    1 1 1

*/

Compilation message

joi2019_ho_t4.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 6 ms 2680 KB Output is correct
13 Correct 6 ms 2680 KB Output is correct
14 Correct 7 ms 2680 KB Output is correct
15 Correct 6 ms 2684 KB Output is correct
16 Incorrect 6 ms 2680 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 6 ms 2680 KB Output is correct
13 Correct 6 ms 2680 KB Output is correct
14 Correct 7 ms 2680 KB Output is correct
15 Correct 6 ms 2684 KB Output is correct
16 Incorrect 6 ms 2680 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 6 ms 2680 KB Output is correct
13 Correct 6 ms 2680 KB Output is correct
14 Correct 7 ms 2680 KB Output is correct
15 Correct 6 ms 2684 KB Output is correct
16 Incorrect 6 ms 2680 KB Output isn't correct
17 Halted 0 ms 0 KB -