Submission #1017731

#TimeUsernameProblemLanguageResultExecution timeMemory
1017731GrayRed-blue table (IZhO19_stones)C++17
100 / 100
52 ms5308 KiB
#include <cassert> #include <iostream> #include <set> #include <vector> #define ll int #define ln "\n" #define ff first #define ss second #define ld long double const ll INF = 1e9; const ll MOD = 1e9+7; using namespace std; void solve(){ ll n, m; cin >> n >> m; ll nform = n/2+1, mforn=m/2+1; cout << max((n-nform)*m/mforn+m,(m-mforn)*n/nform+n) << ln; if ((n-nform)*m/mforn+m>(m-mforn)*n/nform+n){ vector<vector<ll>> ans(n, vector<ll>(m)); multiset<pair<ll, ll>> vac; for (ll i=0; i<(n-nform)*m/mforn; i++){ vac.insert({0, i}); } for (ll j=0; j<m; j++){ for (ll i=0; i<n-nform; ++i){ auto cur = *vac.begin(); vac.erase(vac.begin()); assert(ans[cur.ss][j]==0); ans[cur.ss][j]=2; vac.insert({cur.ff+1, cur.ss}); } } for (ll i=0; i<n; i++){ for (ll j=0; j<m; j++){ cout << (ans[i][j]==2?"+":"-"); } cout << ln; } }else{ vector<vector<ll>> ans(n, vector<ll>(m)); multiset<pair<ll, ll>> vac; for (ll i=0; i<(m-mforn)*n/nform; i++){ vac.insert({0, i}); } for (ll i=0; i<n; i++){ for (ll j=0; j<m-mforn; ++j){ auto cur = *vac.begin(); vac.erase(vac.begin()); assert(ans[i][cur.ss]==0); ans[i][cur.ss]=2; vac.insert({cur.ff+1, cur.ss}); } } for (ll i=0; i<n; i++){ for (ll j=0; j<m; j++){ cout << (ans[i][j]==2?"-":"+"); } cout << ln; } } } void setIO(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int main(){ setIO(); ll t=1; cin >> t; while (t--) solve(); }
#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...