답안 #749054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
749054 2023-05-27T09:35:56 Z 1075508020060209tc Coin Collecting (JOI19_ho_t4) C++14
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long

int n;
int freq[4][500005];
int ps[3][500005];
int ans;
signed main(){
cin>>n;
ans=0;
for(int i=1;i<=n*2;i++){
    int a;int b;
    cin>>a>>b;
    if(b<=1){
        ans+=abs(b-1);
        b=1;
    }else{
        ans+=abs(b-2);
        b=2;
    }
    if(a<=1){
        ans+=abs(1-a);
        a=1;
    }
    if(a>=n){
        ans+=abs(n-a);
        a=n;
    }
    freq[b][a]++;
}

for(int i=1;i<=n;i++){
    ps[1][i]=ps[1][i-1]+freq[1][i];
    ps[2][i]=ps[2][i-1]+freq[2][i];
    ps[3][i]=ps[1][i]+ps[2][i];
}


int cnta=0;int cntb=0;
int lst=0;
for(int i=1;i<=n;i++){


    if(ps[3][i]-i*2==0){
        ans+=abs(ps[2][i]-ps[2][lst]-(i-lst) );
    }
    ans+=abs(ps[3][i]-i*2);
    if(ps[3][i]-i*2==0){
        lst=i;
    }
}
cout<<ans<<endl;




}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:40:5: warning: unused variable 'cnta' [-Wunused-variable]
   40 | int cnta=0;int cntb=0;
      |     ^~~~
joi2019_ho_t4.cpp:40:16: warning: unused variable 'cntb' [-Wunused-variable]
   40 | int cnta=0;int cntb=0;
      |                ^~~~
joi2019_ho_t4.cpp:36:9: warning: array subscript 3 is above array bounds of 'long long int [3][500005]' [-Warray-bounds]
   36 |     ps[3][i]=ps[1][i]+ps[2][i];
      |     ~~~~^
joi2019_ho_t4.cpp:7:5: note: while referencing 'ps'
    7 | int ps[3][500005];
      |     ^~
joi2019_ho_t4.cpp:45:12: warning: array subscript 3 is above array bounds of 'long long int [3][500005]' [-Warray-bounds]
   45 |     if(ps[3][i]-i*2==0){
      |        ~~~~^
joi2019_ho_t4.cpp:7:5: note: while referencing 'ps'
    7 | int ps[3][500005];
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -