Submission #204126

# Submission time Handle Problem Language Result Execution time Memory
204126 2020-02-24T13:28:24 Z tduong0806 Coin Collecting (JOI19_ho_t4) C++14
0 / 100
6 ms 376 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)
        {
            if(abs(s1)>abs(s2)) s1+=s2,s2=0;
            else s2+=s1,s1=0;
        }
        if(s1>0&&s2<0)
        {
            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()
      ^
# 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 6 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Incorrect 5 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 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 6 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Incorrect 5 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 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 6 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Incorrect 5 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -