Submission #345443

#TimeUsernameProblemLanguageResultExecution timeMemory
345443Valera_GrinenkoRed-blue table (IZhO19_stones)C++17
100 / 100
115 ms2668 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include <iostream> #include <fstream> #include <algorithm> #include <vector> #include <set> #include <stack> #include <map> #include <unordered_map> #include <iomanip> #include <cmath> #include <queue> #include <bitset> #include <numeric> #include <array> #include <cstring> #include <random> #include <chrono> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) typedef long long ll; typedef long double ld; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template<class T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 0; cin >> t; while(t--) { int n = 0, m = 0; cin >> n >> m; bool sw = false; if(n > m) { swap(n, m); sw = true; } vector<vector<char> > ans(n, vector<char>(m, '-')); vector<int> cntc(m); int cpos = 0; for(int i = 0; i < n; i++) { int cur = 0; for(int j = 0; j < m; j++) { cpos = (cpos + 1) % m; if(cntc[cpos] < (n - 1) / 2) { ans[i][cpos] = '+'; cntc[cpos]++; cur++; if(cur == m / 2 + 1) break; } } } if(sw) { vector<vector<char> > newans(m, vector<char>(n)); for(int i = 0; i < m; i++) for(int j = 0; j < n; j++) newans[i][j] = (ans[j][i] ^ '-' ^ '+'); swap(ans, newans); swap(n, m); } int a = 0, b = 0; for(int i = 0; i < n; i++) { int am0 = 0, am1 = 0; for(int j = 0; j < m; j++) { am0 += (ans[i][j] == '-'); am1 += (ans[i][j] == '+'); } a += (am1 > am0); } for(int j = 0; j < m; j++) { int am0 = 0, am1 = 0; for(int i = 0; i < n; i++) { am0 += (ans[i][j] == '-'); am1 += (ans[i][j] == '+'); } b += (am0 > am1); } cout << (a + b) << '\n'; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) cout << ans[i][j]; cout << endl; } } return 0; } /* 0 = - 1 = + */

Compilation message (stderr)

stones.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
#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...