답안 #204118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204118 2020-02-24T13:04:57 Z tduong0806 Coin Collecting (JOI19_ho_t4) C++14
0 / 100
5 ms 380 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]++;
}
void movel(int i,int j)
{
    if(f[i][j]<2) return;
    if(!f[i][3-j]) f[i][3-j]=1,f[i][j]--,ans++;
    int c=max(0ll,min(f[i][j]-1,2*(n-i)-s[i+1]));
    f[i][j]-=c;
    f[i+1][j]+=c;
    ans+=c;
}
void mover(int i,int j)
{
    if(f[i][j]<2) return;
    if(!f[i][3-j]) f[i][3-j]=1,f[i][j]--,ans++;
    ans+=(f[i][j]-1);
    f[i-1][j]+=(f[i][j]-1);
    f[i][j]=1;
}
main()
{
    //freopen("JOI2019.inp","r",stdin);
    n=in;
    forinc(i,1,2*n)
    {
        int x=in,y=in;
        add(x,y);
    }
    fordec(i,n,1) s[i]=s[i+1]+f[i][1]+f[i][2];
    forinc(i,1,n) movel(i,1),movel(i,2);
    fordec(i,n,1) mover(i,1),mover(i,2);
    cout<<ans<<"\n";
}

Compilation message

joi2019_ho_t4.cpp:50: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 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 380 KB Output is correct
6 Incorrect 5 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 380 KB Output is correct
6 Incorrect 5 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 380 KB Output is correct
6 Incorrect 5 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -