답안 #173213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173213 2020-01-03T15:18:55 Z mosiashvililuka Red-blue table (IZhO19_stones) C++14
100 / 100
110 ms 2608 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+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

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);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 1500 KB Output is correct
2 Correct 96 ms 1988 KB Output is correct
3 Correct 93 ms 2220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 1512 KB Output is correct
2 Correct 85 ms 1912 KB Output is correct
3 Correct 77 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 89 ms 1500 KB Output is correct
6 Correct 96 ms 1988 KB Output is correct
7 Correct 93 ms 2220 KB Output is correct
8 Correct 92 ms 1512 KB Output is correct
9 Correct 85 ms 1912 KB Output is correct
10 Correct 77 ms 1656 KB Output is correct
11 Correct 20 ms 632 KB Output is correct
12 Correct 87 ms 1960 KB Output is correct
13 Correct 85 ms 2092 KB Output is correct
14 Correct 63 ms 1784 KB Output is correct
15 Correct 110 ms 2608 KB Output is correct
16 Correct 86 ms 1928 KB Output is correct
17 Correct 36 ms 1416 KB Output is correct