제출 #749058

#제출 시각아이디문제언어결과실행 시간메모리
7490581075508020060209tcCoin Collecting (JOI19_ho_t4)C++14
0 / 100
1 ms340 KiB
#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]-ps[3][lst]-(i-lst)*2);
    if(ps[3][i]-ps[3][lst]-(i-lst)*2==0){
        lst=i;
    }
}
cout<<ans<<endl;




}

컴파일 시 표준 에러 (stderr) 메시지

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];
      |     ^~
joi2019_ho_t4.cpp:48:27: warning: array subscript 3 is above array bounds of 'long long int [3][500005]' [-Warray-bounds]
   48 |     ans+=abs(ps[3][i]-ps[3][lst]-(i-lst)*2);
      |                       ~~~~^
joi2019_ho_t4.cpp:7:5: note: while referencing 'ps'
    7 | int ps[3][500005];
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...