Submission #683727

# Submission time Handle Problem Language Result Execution time Memory
683727 2023-01-19T08:39:24 Z NintsiChkhaidze Red-blue table (IZhO19_stones) C++14
32 / 100
25 ms 3900 KB
#include <bits/stdc++.h>
#define ll long long
#define s second
#define pb push_back
#define f first
#define left (h<<1),l,((l+r)>>1)
#define right ((h<<1)|1),((l+r)>>1) + 1,r
#define pii pair<int,int>
// #define int ll // ? 
using namespace std;
 
const int NN = 1005,mod = 1000000007; // ?
int a[NN][NN],y[NN],x[NN],f[NN];
int ans,n,m;
 
void solve(){
    ans = 0;
    if (m >= n){
        int N = n - n/2 - 1,P = 0;
        for (int p = 0; p <= m; p++){
            int k = m/2 + 1 - p,ig = 0;
            if (k) ig = min(n, ((m - p)/k)*N);
            else ig = n;
            if (ans < m - p + ig){
                P = p;
                ans = m - p + ig;
            }
        }

        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                a[i][j] = 0;

        for (int i = 1; i <= n; i++)    
            for (int j = 1; j <= P; j++)
                a[i][j] = 1;

        int k = m/2 + 1 - P;
        for (int j = 1; j <= P; j++) y[j] = 0;
        for (int j = P+1; j <= m; j++) y[j] = N;
        for (int i = 1; i <= n; i++){
            int cnt = 0;
            for (int j = 1; j <= m; j++) f[j] = 0;
            for (int j = 1; j <= m; j++){
                if (y[j]) {
                    --y[j];
                    f[j] = 1;
                    cnt++;
                }
                if (cnt == k) break;
            }
            if (cnt < k) break;
 
            for (int j = 1; j <= m; j++)
                if (f[j]) a[i][j] = 1;
        }
        return;
    }
    
    
    int N = m - m/2 - 1,P = 0;
    for (int p = 0; p <= n; p++){
        int k = n/2 + 1 - p,ig = 0;
        if (k) ig = min(n, ((n - p)/k)*N);
        else ig = m;
        if (ans < n - p + ig){
            P = p;
            ans = n - p + ig;
        }
    }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            a[i][j] = 1;

    for (int i = 1; i <= P; i++)    
        for (int j = 1; j <= m; j++)
            a[i][j] = 0;

    int k = n/2 + 1 - P;
    for (int i = 1; i <= P; i++) x[i] = 0;
    for (int i = P+1; i <= m; i++) x[i] = N;

    for (int j = 1; j <= m; j++){
        int cnt=0;
        for (int i = 1; i <= n; i++) f[i] = 0;
        for (int i = 1; i <= n; i++){
            if (x[i]){
                --x[i];
                f[i] = 1;
                ++cnt;
            }
            if (cnt == k) break;
        }
        if (cnt < k) break;
 
        for (int i = 1; i <= n; i++){
            if (f[i]) a[i][j] = 0;
        }
    }
}
signed main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
 
    int T;
    cin>>T;
 
    while (T--){
        cin>>n>>m;
        solve();
        cout<<ans<<endl;
        for (int i = 1; i <= n; i++){
            for (int j = 1; j <= m; j++){
                if (a[i][j]) cout<<"+";
                else cout<<"-";
            }
            cout<<"\n";
        }
        
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB in the table A+B is not equal to 17
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 2 ms 512 KB in the table A+B is not equal to 17
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 1652 KB in the table A+B is not equal to 150
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1816 KB Output is correct
2 Correct 20 ms 3900 KB Output is correct
3 Correct 23 ms 3268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 2 ms 512 KB in the table A+B is not equal to 17
4 Halted 0 ms 0 KB -