답안 #204139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204139 2020-02-24T14:38:04 Z nubboiiiii Coin Collecting (JOI19_ho_t4) C++14
0 / 100
6 ms 2680 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()
      ^
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("test.inp","r",stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Incorrect 6 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Incorrect 6 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Incorrect 6 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -