Submission #335822

# Submission time Handle Problem Language Result Execution time Memory
335822 2020-12-14T04:23:47 Z beksultan04 Red-blue table (IZhO19_stones) C++14
100 / 100
49 ms 2412 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 1e6+12,INF=1e9+7;
int m1[N],p[N];
char q[1001][1001];
main(){
    int t;
    scan1(t)
    while (t--){
        int i,j,n,m,ans=0;
        scan2(n,m)
        if (min(n,m) <= 4){
            if (n <= m){
                for (i=0;i<n;++i){
                    for (j=0;j<m;++j){
                        if (i < n/2+1){
                            q[i][j]='-';
                            m1[j]++;
                        }
                        else {
                            q[i][j]='+';
                            p[i]++;

                        }
                    }
                }
            }
            else {
                for (i=0;i<n;++i){
                    for (j=0;j<m;++j){
                        if (j < m/2+1){
                            q[i][j]='+';
                            p[i]++;
                        }
                        else {
                            m1[j]++;
                            q[i][j]='-';
                        }
                    }
                }
            }
            ans = max(n,m);
            ans += min(n-1,m-1)/2;
            cout <<ans<<"\n";
            for (i=0;i<n;++i){
                for (j=0;j<m;++j){
                    cout <<q[i][j];
                }
                endi;
            }
        }
        else if (min(n,m)<=6){
            if (n <= m){
                int cnt=0;
                for (i=0;i<n;++i){
                    for (j=0;j<m;++j){
                        q[i][j]='-';
                    }
                }
                i=0;
                j=0;
                int mod = m/2+1;
                while (i < (n-1)/2+1){
                    q[i][j]='+';
                    cnt++;
                    j++;
                    j%=m;
                    if (cnt%mod==0)
                        i++;
                    cnt%=mod;
                }
                ans = m;
                ans+=(n-1)/2+1;
                cout <<ans<<"\n";
                for (i=0;i<n;++i){
                    for (j=0;j<m;++j){
                        cout <<q[i][j];
                    }
                    endi;
                }
            }
            else {

                int cnt=0;
                for (i=0;i<n;++i){
                    for (j=0;j<m;++j){
                        q[i][j]='+';
                    }
                }
                i=0;
                j=0;
                int mod = n/2+1;
                while (j < (m-1)/2+1){
                    q[i][j]='-';
                    cnt++;
                    i++;
                    i%=n;
                    if (cnt%mod==0)
                        j++;
                    cnt%=mod;
                }
                ans = n;
                ans+=(m-1)/2+1;
                cout <<ans<<"\n";
                for (i=0;i<n;++i){
                    for (j=0;j<m;++j){
                        cout <<q[i][j];
                    }
                    endi;
                }
            }
        }
        else {
            if (n <= m){
                int cnt=0;
                for (i=0;i<n;++i){
                    for (j=0;j<m;++j){
                        q[i][j]='-';
                    }
                }
                i=0;
                j=0;
                int mod = m/2+1;
                ans = m;
                while (i<n){
                    if ((p[j]+1)*2 >= n){
                        break;
                    }
                    q[i][j]='+';
                    p[j]++;
                    m1[i]++;
                    cnt++;
                    j++;
                    j%=m;
                    if (cnt%mod==0){
                        i++;
                    }
                    cnt%=mod;
                }
                for (i=0;i<n;++i){
                    if (m1[i] > m-m1[i])ans++;
                }
            }
            else {
                int cnt=0;
                for (i=0;i<n;++i){
                    for (j=0;j<m;++j){
                        q[i][j]='+';
                    }
                }
                i=0;
                j=0;
                int mod = n/2+1;
                ans = n;
                while (1){

                    if ((p[i]+1)*2 >= m){
                        break;
                    }
                    q[i][j]='-';
                    p[i]++;
                    m1[j]++;
                    cnt++;
                    i++;
                    i%=n;
                    if (cnt-mod==0){
                        j++;
                        cnt=0;
                    }
                }
                for (i=0;i<m;++i){
                    if (m1[i] > n-m1[i])ans++;
                }
            }
            cout <<ans<<"\n";
            for (i=0;i<n;++i){
                p[i]=0;
                for (j=0;j<m;++j){
                    p[j]=0;
                    cout <<q[i][j];
                }
                endi;
            }
        }
        for (i=0;i<n;++i)p[i]=m1[i]=0;
        for (i=0;i<m;++i)p[i]=m1[i]=0;
    }
}

Compilation message

stones.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      |      ^
stones.cpp: In function 'int main()':
stones.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
stones.cpp:20:5: note: in expansion of macro 'scan1'
   20 |     scan1(t)
      |     ^~~~~
stones.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
stones.cpp:23:9: note: in expansion of macro 'scan2'
   23 |         scan2(n,m)
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 1644 KB Output is correct
2 Correct 44 ms 2028 KB Output is correct
3 Correct 39 ms 2156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 1516 KB Output is correct
2 Correct 41 ms 2028 KB Output is correct
3 Correct 36 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 49 ms 1644 KB Output is correct
6 Correct 44 ms 2028 KB Output is correct
7 Correct 39 ms 2156 KB Output is correct
8 Correct 47 ms 1516 KB Output is correct
9 Correct 41 ms 2028 KB Output is correct
10 Correct 36 ms 1644 KB Output is correct
11 Correct 11 ms 620 KB Output is correct
12 Correct 35 ms 1900 KB Output is correct
13 Correct 38 ms 2028 KB Output is correct
14 Correct 29 ms 1772 KB Output is correct
15 Correct 48 ms 2412 KB Output is correct
16 Correct 36 ms 1900 KB Output is correct
17 Correct 15 ms 1404 KB Output is correct