Submission #257116

# Submission time Handle Problem Language Result Execution time Memory
257116 2020-08-03T15:44:22 Z BThero Red-blue table (IZhO19_stones) C++17
100 / 100
19 ms 10240 KB
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int MAXN = (int)1e3 + 5;
const int INF = (int)1e9;

char s[MAXN][MAXN];
int cnt[MAXN];
int n, m;
pii ans;

int calc(int n, int m, vvi &ret) {
  ans = mp(m, 0);
  
  for (int i = 0; i < m; ++i) {
    cnt[i] = n;
  }
  
  for (int step = 1, ptr = 0, col = m; step <= n; ++step) {
    for (int i = 1; i <= m / 2 + 1; ++i) {
      if (--cnt[ptr] <= n / 2) {
        --col;
      }
      
      ptr = (ptr + 1) % m;
    }
    
    ans = max(ans, mp(step + col, step));
  } 
  
  ret = vvi(n, vi(m, 0));
  
  for (int step = 1, ptr = 0; step <= ans.se; ++step) {
    for (int i = 1; i <= m / 2 + 1; ++i) {
      ret[step - 1][ptr] = 1;
      ptr = (ptr + 1) % m;
    }
  }
  
  return ans.fi;
}

void solve() {
  scanf("%d %d", &n, &m);
  vvi Av, Bv;
  int A, B;
  A = calc(n, m, Av);
  B = calc(m, n, Bv);
  
  if (A >= B) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        s[i][j] = (Av[i][j] ? '+' : '-');
      }
      
      s[i][m] = '\0';
    }
  }
  else {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        s[i][j] = (Bv[j][i] ? '-' : '+');
      }
      
      s[i][m] = '\0';
    }
  }
  
  printf("%d\n", max(A, B));
  
  for (int i = 0; i < n; ++i) {
    printf("%s\n", s[i]);
  }
}

int main() {
  int tt;
  scanf("%d", &tt);
  
  while (tt--) {
    solve();
  }

  return 0;
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
stones.cpp: In function 'int main()':
stones.cpp:93:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &tt);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1536 KB Output is correct
2 Correct 16 ms 7296 KB Output is correct
3 Correct 16 ms 7864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1688 KB Output is correct
2 Correct 16 ms 5728 KB Output is correct
3 Correct 13 ms 4208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 19 ms 1536 KB Output is correct
6 Correct 16 ms 7296 KB Output is correct
7 Correct 16 ms 7864 KB Output is correct
8 Correct 17 ms 1688 KB Output is correct
9 Correct 16 ms 5728 KB Output is correct
10 Correct 13 ms 4208 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 14 ms 5376 KB Output is correct
13 Correct 15 ms 4292 KB Output is correct
14 Correct 11 ms 3200 KB Output is correct
15 Correct 19 ms 10240 KB Output is correct
16 Correct 14 ms 7680 KB Output is correct
17 Correct 7 ms 3968 KB Output is correct