Submission #871119

# Submission time Handle Problem Language Result Execution time Memory
871119 2023-11-10T00:17:36 Z ToighetLPHM Coin Collecting (JOI19_ho_t4) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
//#define int long long
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define FOD(i,a,b) for (int i=(a);i>=(b);i--)
#define bit(x,y) ((x)>>(y))&1
#define pb push_back
#define ll long long
#define ii pair < int,int >
#define f first
#define s second
#define M 1000000007
#define N 100005
using namespace std;
int cnt[N][2];
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen(".inp","r",stdin);
    //freopen(".out","w",stdout);
    int n,res=0;
    cin>>n;
    FOR(i,1,2*n) {
        int x,y;
        cin>>x>>y;
        if (x<1) {
            res+=1-x;
            x=1;
        } else
        if (x>n) {
            res+=x-n;
            x=n;
        }
        if (y>2) {
            res+=y-2;
            y=2;
        } else
        if (y<1) {
            res+=1-y;
            y=1;
        }
        ++cnt[x][y];
    }
    int x=0,y=0;
    FOR(i,1,n) {
        --cnt[i][1];
        --cnt[i][2];
        x+=cnt[i][1];
        y+=cnt[i][2];
        if (x<0 && y>0) {
            int z=min(abs(x),abs(y));
            x+=z;
            y-=z;
            res+=z;
        } else
        if (x>0 && y<0) {
            int z=min(abs(x),abs(y));
            x-=z;
            y+=z;
            res+=z;
        }
        res+=abs(x)+abs(y);
    }
    cout<<res;
    return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:47:19: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   47 |         --cnt[i][2];
      |           ~~~~~~~~^
joi2019_ho_t4.cpp:47:19: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -