Submission #375901

#TimeUsernameProblemLanguageResultExecution timeMemory
375901daniel920712Naan (JOI19_naan)C++14
100 / 100
1433 ms164516 KiB
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <algorithm> using namespace std; long long all[2005][2005]; long long sum[2005][2005]={0}; long long tt[2005]={0}; vector < pair < long long , long long > > ans; vector < long long > ans2; bool have[2005]={0}; vector < pair < pair < long long ,long long > , long long > > where[2005]; long long F(long long a,long long b) { if(b==0) return a; return F(b,a%b); } bool cmp(pair < pair < long long ,long long > , long long > a,pair < pair < long long ,long long > , long long > b) { if(a.first.first/a.first.second>b.first.first/b.first.second) return 0; if(a.first.first/a.first.second<b.first.first/b.first.second) return 1; return a.first.first%a.first.second*b.first.second<b.first.first%b.first.second*a.first.second; } int main() { //freopen("03-02.txt","rt",stdin); long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t; scanf("%lld %lld",&N,&M); for(i=0;i<N;i++) { sum[i][0]=0; for(j=0;j<M;j++) { scanf("%lld",&all[i][j]); sum[i][j]=sum[i][j-1]+all[i][j]; } } for(i=0;i<N;i++) { x1=0; y1=1; now=0; for(j=0;j<M;j++) { while((x1+all[i][j]*y1)*N>=(sum[i][M-1])*(now+1)*y1) { x2=(sum[i][M-1])*(now+1)*y1-x1*N; y2=y1*N*all[i][j]; where[now++].push_back(make_pair(make_pair(x2+j*y2,y2),i)); } x1+=y1*all[i][j]; } } for(i=0;i<N;i++) sort(where[i].begin(),where[i].end(),cmp); x1=0; y1=1; for(i=0;i<N;i++) { ok=0; for(auto j:where[i]) { if(have[j.second]||x1/y1>j.first.first/j.first.second||x1/y1==j.first.first/j.first.second&&(x1%y1*j.first.second)>(j.first.first%j.first.second*y1)) continue; ok=1; x1=j.first.first; y1=j.first.second; have[j.second]=1; ans.push_back(make_pair(j.first.first,j.first.second)); ans2.push_back(j.second); break; } if(!ok) return 1; } for(i=0;i<N-1;i++) printf("%lld %lld\n",ans[i].first,ans[i].second); for(auto i:ans2) printf("%lld ",i+1); //for(i=0;i<N-1;i++) printf("%.10f\n",(double) ans[i].first/(double) ans[i].second); //printf("%lld\n",M); return 0; }

Compilation message (stderr)

naan.cpp: In function 'int main()':
naan.cpp:68:103: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   68 |             if(have[j.second]||x1/y1>j.first.first/j.first.second||x1/y1==j.first.first/j.first.second&&(x1%y1*j.first.second)>(j.first.first%j.first.second*y1)) continue;
      |                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
naan.cpp:30:19: warning: unused variable 'a' [-Wunused-variable]
   30 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                   ^
naan.cpp:30:21: warning: unused variable 'b' [-Wunused-variable]
   30 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                     ^
naan.cpp:30:35: warning: unused variable 'c' [-Wunused-variable]
   30 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                                   ^
naan.cpp:30:52: warning: unused variable 'z' [-Wunused-variable]
   30 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                                                    ^
naan.cpp:30:54: warning: unused variable 'x3' [-Wunused-variable]
   30 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                                                      ^~
naan.cpp:30:57: warning: unused variable 'y3' [-Wunused-variable]
   30 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                                                         ^~
naan.cpp:30:60: warning: unused variable 't' [-Wunused-variable]
   30 |     long long N,M,a,b,x1,y1,x2,y2,c,i,j,ok=1,now=0,z,x3,y3,t;
      |                                                            ^
naan.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |     scanf("%lld %lld",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
naan.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |             scanf("%lld",&all[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...