Submission #684532

# Submission time Handle Problem Language Result Execution time Memory
684532 2023-01-21T13:58:33 Z NintsiChkhaidze Red-blue table (IZhO19_stones) C++14
27 / 100
45 ms 2724 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
const int NN = 2005;
int a[NN][NN],y[NN],x[NN],f[NN],ans,n,m,b[NN][NN];
 
void solve(){
    ans=0;
    /*
    //sworia
    int N = n - n/2 - 1,P = 0; // N -> ramdeni cell sheudzlia daakldes
    for (int p = 0; p <= m; p++){
        int k = m/2 + 1 - p,ig = 0; // k -> ramdeni schirdeba
 
        if (k>0) ig = min(n, ((m - p)/k)*N);
        else ig = n;
 
        if (ans < m - p + ig){
            P = p;
            ans = m - p + ig;
        }
    }
    
    //sworia
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            a[i][j] = 0;
    
    //sworia
    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-n/2-1;
    for (int i = 1; i <= n; i++){
        int cnt = 0;
        for (int j = 1; j <= m; j++) f[j] = 0;
        for (int j = P+1; j <= m; j++){
            if (y[j]>0) {
                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;
    }
    
    for(int i=1;i<=n;i++)
        for(int j=1;j<=P;j++)
            a[i][j]=1;
            
    int ans1=ans;
    */
    
    //////////////////////////////////////
    ans=0;
    int ans1=0;

    //sworia
    int N = m - m/2 - 1,P = 0;
    for (int p = 0; p <= n; p++){
        int k = max(0LL,n/2 + 1 - p),ig = 0;
        int rm = (n - p)*(m - m/2 - 1);
        if (k) ig = min(m, rm/k);
        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++)
            b[i][j] = 1;
    
    //sworia
    int k = n/2 + 1 - P;
    for (int i = 1; i <= P; i++) x[i] = 0;
    for (int i = P+1; i <= n; i++) x[i] = N;
    
    //sworia
    for (int j = 1; j <= m; j++){
        int cnt=0;
        for (int i = 1; i <= n; i++) f[i] = 0;
        for (int i = P+1; i <= n; i++){
            if (x[i]>0){
                x[i]--;
                f[i] = 1;
                cnt++;
            }
            if (cnt == k) break;
        }
        if (cnt < k) break;
        for (int i = 1; i <= n; i++)
            if (f[i]) b[i][j] = 0;
    }
    
    for(int i=1;i<=P;i++)
        for(int j=1;j<=m;j++)
            b[i][j]=0;
 
    int ans2 = ans;
    if (ans1 < ans2){
        ans = ans2;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                a[i][j] = b[i][j];
    }else{
        ans = ans1;
    }
 
}
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<<endl;
        }
        
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 6 ms 724 KB Output is correct
4 Incorrect 10 ms 796 KB in the table A+B is not equal to 41
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 2220 KB in the table A+B is not equal to 78
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 2724 KB in the table A+B is not equal to 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 6 ms 724 KB Output is correct
4 Incorrect 10 ms 796 KB in the table A+B is not equal to 41
5 Halted 0 ms 0 KB -