Submission #923621

#TimeUsernameProblemLanguageResultExecution timeMemory
923621GrindMachineRed-blue table (IZhO19_stones)C++17
26 / 100
21 ms6828 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(x) 42 #endif /* */ const int MOD = 1e9 + 7; const int N = 1e5 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; void solve(int test_case) { ll n,m; cin >> n >> m; if(n == 1){ cout << m << endl; rep1(j,m) cout << "-"; cout << endl; return; } if(m == 1){ cout << n << endl; rep1(i,n) cout << "+" << endl; return; } if((n&1) and (m&1)){ ll a[n+5][m+5]; memset(a,0,sizeof a); rep1(i,n) a[i][1] = 1; rep1(i,n-1){ if(i&1){ for(int j = 2; j <= ceil2(m,2); ++j){ a[i][j] = 1; } } else{ for(int j = ceil2(m,2)+1; j <= m; ++j){ a[i][j] = 1; } } } ll ans = n+m-2; cout << ans << endl; rep1(i,n){ rep1(j,m){ if(a[i][j] == 1) cout << "+"; else cout << "-"; } cout << endl; } return; } if(n != m) return; if(n == 2){ ll ans = 2; cout << ans << endl; rep1(i,n){ rep1(j,m){ cout << '+'; } cout << endl; } return; } if(n == 4){ ll a[n+5][m+5]; memset(a,0,sizeof a); rep1(i,n){ rep1(j,m/2+1){ a[i][j] = 1; } } ll ans = n+1; cout << ans << endl; rep1(i,n){ rep1(j,m){ if(a[i][j] == 1) cout << "+"; else cout << "-"; } cout << endl; } return; } if(n == 6){ ll a[n+5][m+5]; memset(a,0,sizeof a); rep1(i,n){ rep1(j,m/2){ a[i][j] = 1; } } a[1][4] = a[2][4] = 1; a[3][5] = a[4][5] = 1; a[5][6] = a[6][6] = 1; ll ans = n+m/2; cout << ans << endl; rep1(i,n){ rep1(j,m){ if(a[i][j] == 1) cout << "+"; else cout << "-"; } cout << endl; } return; } ll a[n+5][m+5]; n--, m--; memset(a,0,sizeof a); rep1(i,n+1) a[i][1] = 1; rep1(i,n-1){ if(i&1){ for(int j = 2; j <= ceil2(m,2); ++j){ a[i][j] = 1; } } else{ for(int j = ceil2(m,2)+1; j <= m; ++j){ a[i][j] = 1; } } } n++, m++; rep1(i,n) a[i][m] = 1; ll ans = n+m-4; cout << ans << endl; rep1(i,n){ rep1(j,m){ if(a[i][j] == 1) cout << "+"; else cout << "-"; } cout << endl; } /* int n,m; cin >> n >> m; int a[n][m]; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int ans = 0; rep(iter,1e7){ rep(i,n){ rep(j,m){ a[i][j] = rng()&1; } } int val = 0; rep(i,n){ int cnt_one = 0; rep(j,m){ cnt_one += a[i][j]; } if(cnt_one*2 > m){ val++; } } rep(j,m){ int cnt_zero = 0; rep(i,n){ cnt_zero += a[i][j]^1; } if(cnt_zero*2 > n){ val++; } } amax(ans,val); // if(val == 10){ // rep(i,n){ // rep(j,m){ // cout << a[i][j]; // } // cout << endl; // } // cout << endl; // } } cout << ans << endl; */ } int main() { fastio; int t = 1; cin >> t; rep1(i, t) { solve(i); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...