제출 #1315759

#제출 시각아이디문제언어결과실행 시간메모리
1315759cosminvixtor지구 온난화 (NOI13_gw)C++20
6 / 40
1096 ms6868 KiB
#include <iostream> using namespace std; void bubble_sort(int *A,int n) { int i,chair,done; do { done=1; for (i=0;i<n-1;i++) { if (A[i]<A[i+1]) { chair=A[i]; A[i]=A[i+1]; A[i+1]=chair; done=0; } } } while (!done); } void printv(int *A,int n) { for (int i=0;i<n;i++) { printf("%d ",A[i]); } printf("\n"); } int main() { int *L,*T,tidx,pidx,vidx,*V,*P,n,i,j,nr,hp,cnt,islands,maxislands; scanf("%d",&n); L=(int*)calloc(n,sizeof(int)); T=(int*)calloc(n,sizeof(int)); j=1; scanf("%d",L); for (i=1;i<n;i++) { scanf("%d",&nr); if (nr!=L[j-1]) L[j++]=nr; } tidx=0; if (L[0]>L[1]) { T[tidx++]=L[0]; } for (i=1;i<n-1;i++) { if (L[i-1]<L[i] && L[i]>L[i+1]) T[tidx++]=L[i]; else if (L[i-1]>L[i] && L[i]<L[i+1]) T[tidx++]=L[i]; } if (L[n-2]<L[n-1]) { T[tidx++]=L[n-1]; } free(L); V=(int*)calloc(tidx/2+1,sizeof(int)); P=(int*)calloc(tidx/2+2,sizeof(int)); vidx=0; pidx=0; for (i=0;i<tidx;i+=2) P[pidx++]=T[i]; for (i=1;i<tidx;i+=2) V[vidx++]=T[i]; free(T); bubble_sort(P,pidx); bubble_sort(V,vidx); //printv(P,pidx); //printv(V,vidx); islands=0; maxislands=0; i=0; j=0; while (i<pidx || j<vidx) { if (P[i]>V[j]) { hp=P[i]; cnt=1; while (P[++i]==hp) cnt++; islands+=cnt; } else { hp=V[j]; cnt=1; while (V[++j]==hp) cnt++; islands-=cnt; } if (islands>maxislands) maxislands=islands; } printf("%d\n",maxislands); }

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

gw.cpp: In function 'int main()':
gw.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
gw.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d",L);
      |     ~~~~~^~~~~~~~
gw.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d",&nr);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...