Submission #173191

#TimeUsernameProblemLanguageResultExecution timeMemory
173191mosiashvililukaRed-blue table (IZhO19_stones)C++14
0 / 100
69 ms1716 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+n%2; zm=m/2+m%2; 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; mid=a*x/z; ans=a+mid; if(pas<ans){ c=a; d=mid; pas=ans; } } } printf("%d\n",pas); a=c;mid=d; 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; mid=a*x/z; ans=a+mid; s.clear(); for(i=1; i<=mid; i++) s.insert(make_pair(z,i)); e=1; while(e<=a){ pi=0; d=x; while(d>x&&s.size()>0){ it=s.end();it--; ch[e][(*it).second]='+'; 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...