Submission #173191

# Submission time Handle Problem Language Result Execution time Memory
173191 2020-01-03T14:46:08 Z mosiashvililuka Red-blue table (IZhO19_stones) C++14
0 / 100
69 ms 1716 KB
#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

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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB in the table A+B is not equal to 6
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB in the table A+B is not equal to 46
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB in the table A+B is not equal to 6
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 1528 KB in the table A+B is not equal to 539
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 1716 KB in the table A+B is not equal to 169
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB in the table A+B is not equal to 6