Submission #1025923

# Submission time Handle Problem Language Result Execution time Memory
1025923 2024-07-17T11:17:28 Z hasan2006 Red-blue table (IZhO19_stones) C++17
100 / 100
24 ms 11100 KB
#include <bits/stdc++.h>

using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 1e3 + 9 , mod = 1e9 + 7;
int a[N][N] , b[N] , dp[N] , c[N] , d[N][N] , ans[N][N] ;


int solve(ll n , ll m)
{
    ll  q , i , j ,l ,r , x , y , s = 0 , f , k ,  mn = 1e18, mx = 0 ;
    for(i = 1; i <= n; i++)
        for(j = 1; j <= m; j++)
            a[i][j] = 0 ,b[i] = 0 ,  c[j] = n;
    pair<ll,ll> ans = {m , 0};
    x = 1;
    s = m;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m / 2+ 1; j ++){
            if(--c[x] <= n / 2)
                s--;
            x++;
            if(x == m + 1)
                x = 1;
        }
        ans = max(ans , {i + s ,i});
    }
    x = 1;
    for(i = 1; i <= ans.se; i++){
        for(j = 1; j <= m / 2 + 1; j++){
            a[i][x] = 1;
            x ++;
            if(x == m + 1)
                x = 1;
        }
    }
    return ans.fi;
}

int main(){
    TL;
    int t = 1;
    cin>>t;
    while(t--)
     {
        ll n , m;
        cin>>n>>m;
        ll s = solve(n , m);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++)
            ans[i][j] = 1 - a[i][j];
        ll f = solve(m , n);
        if(f >= s){
            s = f;
            for(int i = 1; i <= n; i++)
                for(int j = 1; j <= m; j++)
                    ans[i][j] = a[j][i];
        }
        cout<<s<<"\n";
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++)
            cout<<(ans[i][j] == 1 ? "-" : "+");
        cout<<"\n";
        }
     }
}
// Author : حسن

Compilation message

stones.cpp: In function 'int solve(long long int, long long int)':
stones.cpp:27:9: warning: unused variable 'q' [-Wunused-variable]
   27 |     ll  q , i , j ,l ,r , x , y , s = 0 , f , k ,  mn = 1e18, mx = 0 ;
      |         ^
stones.cpp:27:20: warning: unused variable 'l' [-Wunused-variable]
   27 |     ll  q , i , j ,l ,r , x , y , s = 0 , f , k ,  mn = 1e18, mx = 0 ;
      |                    ^
stones.cpp:27:23: warning: unused variable 'r' [-Wunused-variable]
   27 |     ll  q , i , j ,l ,r , x , y , s = 0 , f , k ,  mn = 1e18, mx = 0 ;
      |                       ^
stones.cpp:27:31: warning: unused variable 'y' [-Wunused-variable]
   27 |     ll  q , i , j ,l ,r , x , y , s = 0 , f , k ,  mn = 1e18, mx = 0 ;
      |                               ^
stones.cpp:27:43: warning: unused variable 'f' [-Wunused-variable]
   27 |     ll  q , i , j ,l ,r , x , y , s = 0 , f , k ,  mn = 1e18, mx = 0 ;
      |                                           ^
stones.cpp:27:47: warning: unused variable 'k' [-Wunused-variable]
   27 |     ll  q , i , j ,l ,r , x , y , s = 0 , f , k ,  mn = 1e18, mx = 0 ;
      |                                               ^
stones.cpp:27:52: warning: unused variable 'mn' [-Wunused-variable]
   27 |     ll  q , i , j ,l ,r , x , y , s = 0 , f , k ,  mn = 1e18, mx = 0 ;
      |                                                    ^~
stones.cpp:27:63: warning: unused variable 'mx' [-Wunused-variable]
   27 |     ll  q , i , j ,l ,r , x , y , s = 0 , f , k ,  mn = 1e18, mx = 0 ;
      |                                                               ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 2 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5724 KB Output is correct
2 Correct 22 ms 10588 KB Output is correct
3 Correct 17 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 7700 KB Output is correct
2 Correct 24 ms 9808 KB Output is correct
3 Correct 22 ms 9400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 2 ms 4696 KB Output is correct
5 Correct 21 ms 5724 KB Output is correct
6 Correct 22 ms 10588 KB Output is correct
7 Correct 17 ms 10840 KB Output is correct
8 Correct 23 ms 7700 KB Output is correct
9 Correct 24 ms 9808 KB Output is correct
10 Correct 22 ms 9400 KB Output is correct
11 Correct 10 ms 2648 KB Output is correct
12 Correct 16 ms 10076 KB Output is correct
13 Correct 17 ms 10572 KB Output is correct
14 Correct 13 ms 9816 KB Output is correct
15 Correct 20 ms 11100 KB Output is correct
16 Correct 15 ms 10588 KB Output is correct
17 Correct 7 ms 9304 KB Output is correct