제출 #345441

#제출 시각아이디문제언어결과실행 시간메모리
345441Valera_GrinenkoRed-blue table (IZhO19_stones)C++17
100 / 100
96 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 n = 0, m = 0; // // cin >> n >> m; // // vector<vector<vector<int> > > ans; // // int ansval = 0; // // int tot = n * m; // // for(int it = 0; it < (1 << tot); it++) { // vector<vector<int> > cur(n, vector<int>(m)); // for(int i = 0; i < n; i++) // for(int j = 0; j < m; j++) // cur[i][j] = ((it >> (i * m + j)) & 1); // 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 += (cur[i][j] == 0); am1 += (cur[i][j] == 1); } // a += (am1 > am0); // } // for(int j = 0; j < m; j++) { // int am0 = 0, am1 = 0; // for(int i = 0; i < n; i++) { am0 += (cur[i][j] == 0); am1 += (cur[i][j] == 1); } // b += (am0 > am1); // } // if(a + b > ansval) { // // ans.clear(); // // ans.pb(cur); // ansval = a + b; // } // } // // cout << ansval << '\n'; // // for(auto& x : ans) { // for(auto& i : x) { // for(auto& j : i) cout << (j == 0 ? '-' : '+'); // cout << endl; // } // cout << endl; // } 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 = + */

컴파일 시 표준 에러 (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...