Submission #345443

# Submission time Handle Problem Language Result Execution time Memory
345443 2021-01-07T10:28:05 Z Valera_Grinenko Red-blue table (IZhO19_stones) C++17
100 / 100
115 ms 2668 KB
#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

stones.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 14 ms 364 KB Output is correct
4 Correct 19 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 1388 KB Output is correct
2 Correct 45 ms 1756 KB Output is correct
3 Correct 51 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 1424 KB Output is correct
2 Correct 37 ms 1516 KB Output is correct
3 Correct 36 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 14 ms 364 KB Output is correct
4 Correct 19 ms 364 KB Output is correct
5 Correct 115 ms 1388 KB Output is correct
6 Correct 45 ms 1756 KB Output is correct
7 Correct 51 ms 2668 KB Output is correct
8 Correct 79 ms 1424 KB Output is correct
9 Correct 37 ms 1516 KB Output is correct
10 Correct 36 ms 1352 KB Output is correct
11 Correct 41 ms 620 KB Output is correct
12 Correct 40 ms 2060 KB Output is correct
13 Correct 44 ms 1804 KB Output is correct
14 Correct 37 ms 1316 KB Output is correct
15 Correct 42 ms 2412 KB Output is correct
16 Correct 40 ms 1772 KB Output is correct
17 Correct 18 ms 1388 KB Output is correct