Submission #173213

#TimeUsernameProblemLanguageResultExecution timeMemory
173213mosiashvililukaRed-blue table (IZhO19_stones)C++14
100 / 100
110 ms2608 KiB
#include<bits/stdc++.h> using namespace std; int a,b,c,d,e,tes,t,n,m,i,j,z,x,mid,ans,pas,zn,zm,pi; char ch[1009][1009]; pair <int, int> p[1009]; set <pair <int, int> > s; set <pair <int, int> >::iterator it; int main(){ scanf("%d\n",&tes); for(t=1; t<=tes; t++){ scanf("%d %d\n",&n,&m); zn=n/2+1; zm=m/2+1; pas=0; for(i=0; i<=n+1; i++) for(j=0; j<=m+1; j++) ch[i][j]='z'; i=0;j=0; for(a=0; a<=m; a++){ if(m-a>=zm){ ans=a+n; if(pas<ans){ c=a; d=n; pas=ans; } }else{ z=zm-(m-a); x=n-zn; if(z!=0) mid=a*x/z; else mid=0; if(mid>n) mid=n; ans=a+mid; if(pas<ans){ c=a; d=mid; pas=ans; } } } printf("%d\n",pas); a=c;mid=d; // cout<<a<<endl; if(m-a>=zm){ for(i=1; i<=n; i++){ for(j=1; j<=a; j++){ if(i<=n-zn) ch[i][j]='+'; else ch[i][j]='-'; } } for(i=1; i<=n; i++){ for(j=1; j<=m; j++){ if(ch[i][j]=='-') printf("-"); else printf("+"); } printf("\n"); } }else{ z=zm-(m-a); x=n-zn; if(z!=0) mid=a*x/z; else mid=0; if(mid>n) mid=n; ans=a+mid; s.clear(); for(i=1; i<=mid; i++) s.insert(make_pair(z,i)); e=1; while(e<=a){ // cout<<e<<endl; pi=0; d=x; while(d>0&&s.size()>0){ it=s.end();it--; // cout<<(*it).first<<" "<<(*it).second<<" "<<e<<endl; ch[(*it).second][e]='+'; pi++; p[pi]=(*it); s.erase(it); d--; } for(i=1; i<=pi; i++) if(p[i].first>1) s.insert(make_pair(p[i].first-1,p[i].second)); e++; } for(j=1; j<=a; j++){ for(i=1; i<=n; i++){ if(ch[i][j]=='z') ch[i][j]='-'; } } for(i=1; i<=n; i++){ for(j=1; j<=m; j++){ if(ch[i][j]=='-') printf("-"); else printf("+"); } printf("\n"); } } } return 0; }

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d\n",&tes);
     ~~~~~^~~~~~~~~~~~~
stones.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d\n",&n,&m);
         ~~~~~^~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...