Submission #159253

#TimeUsernameProblemLanguageResultExecution timeMemory
159253Dorina_SapfiriaRed-blue table (IZhO19_stones)C++14
100 / 100
48 ms2288 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #define int long long #define pb push_back #define F first #define S second #define pii pair<int, int> using namespace std; void Solve (int n, int m) { if (n>=m) { int ans=n; bool a [n+1][m+1]{}; vector <pii> v; for (int i=1; i<=n; i++) { v.pb({0, i}); } int j=1; int k=m/2+1; k=m-k; int h=n/2+1; // cout << "(" << k << " " << h << ")\n"; while (j<=m) { sort(v.begin(), v.end()); bool fin=0; for (int i=0; i<h; i++) { // cout << "!" << v[i].S << " " << v[i].F << "\n"; if (v[i].F+1>k) { fin=1; break; } } if (fin) { break; } for (int i=0; i<h; i++) { // cout << "--> " << v[i].S << " " << j << "\n"; a[v[i].S][j]=1; v[i].F++; } ans++; j++; // cout << "~~~" << j << "\n"; // cout << "\n"; } cout << ans << "\n"; for (int i=1; i<=n; i++) { for (int j=1; j<=m; j++) { if(a[i][j]) cout << "-"; else cout << "+"; } cout << "\n"; } return; } else { int ans=m; bool a[n+1][m+1]{}; int k=n/2+1; k=n-k; int h=m/2+1; // cout << "(" << k << " " << h << ")\n"; int j=1; vector <pii> v; for (int i=1; i<=m; i++) { v.pb({0, i}); } while (j<=n) { sort(v.begin(), v.end()); bool fin=0; for (int i=0; i<h; i++) { if (v[i].F+1>k) { fin=1; break; } } if (fin) break; for (int i=0; i<h; i++) { a[j][v[i].S]=1; v[i].F++; } ans++; j++; } cout << ans << "\n"; for (int i=1; i<=n; i++) { for (int j=1; j<=m; j++) { if (a[i][j]) cout << '+'; else cout << '-'; } cout << "\n"; } return; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else // freopen("cheval.in", "r", stdin); // freopen("cheval.out", "w", stdout); #endif // LOCAL int t; cin >> t; while (t--) { int n,m; cin >> n >> m; Solve(n, m); // cout << "\n"; } 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...