답안 #345438

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
345438 2021-01-07T10:22:56 Z Valera_Grinenko Red-blue table (IZhO19_stones) C++17
27 / 100
90 ms 1424 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 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);
    for(int i = 0; i < n; i++) {
      int cur = 0;
      for(int j = 0; j < m; j++)
        if(cntc[j] < (n - 1) / 2) {
          ans[i][j] = '+';
          cntc[j]++;
          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")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 13 ms 364 KB Output is correct
4 Incorrect 18 ms 512 KB Wrong answer in test 5 29: 31 < 32
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 1388 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 1424 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 13 ms 364 KB Output is correct
4 Incorrect 18 ms 512 KB Wrong answer in test 5 29: 31 < 32