Submission #280720

# Submission time Handle Problem Language Result Execution time Memory
280720 2020-08-23T01:24:06 Z milleniumEeee Red-blue table (IZhO19_stones) C++14
100 / 100
29 ms 2296 KB
#include <bits/stdc++.h>
//#define int long long
#define pii pair<int, int>
#define fr first
#define sc second
#define all(s) s.begin(), s.end()
#define szof(s) (int)s.size()
#define Ok puts("Ok")
using namespace std;
  
const int N = (int)1e3 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = (int)1e9 + 9;
  
int tests = 1;
int n, m, ans;
char a[N][N], c[N][N];
vector <pair<int, int>> row, col;
  
void init() {
  row.clear();
  col.clear();
  ans = 0;
}
  
inline void solve() {
  init();
  cin >> n >> m;
  
  if (m >= n) {
    ans = m;
    int can = n - (n / 2 + 1);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        c[i][j] = '-';
      }
    }
  
    for (int j = 1; j <= m; j++) {
      col.push_back({j, can});
    }
  
    int need = m / 2 + 1;
    for (int i = 1; i <= n; i++) {
      if (col.empty() || col.size() < need) {
        break;
      }
      int cnt = 0;
      sort (all(col), [&](pii A, pii B) {
          return A.sc > B.sc;
        });
      for (int j = 0; j < need; j++) {
        if (col[j].sc) {
          cnt++;
        }
      }
      if (cnt == need) {
        ans++;
        for (int j = 0; j < need; j++) {
          c[i][col[j].fr] = '+';
          col[j].sc--;
        }
      } else {
        break;
      }
  
      while (!col.empty() && col.back().sc == 0) {
        col.pop_back();
      }
    }
  }
  else {
    ans = n;
    int can = m - (m / 2 + 1);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        c[i][j] = '+';
      }
    }
  
    for (int i = 1; i <= n; i++) {
      row.push_back({i, can});
    }
  
    int need = n / 2 + 1;
    for (int j = 1; j <= m; j++) {
      if (row.empty() || row.size() < need) {
        break;
      }
  
      int cnt = 0;
      sort (all(row), [&](pii A, pii B) {
        return A.sc > B.sc;
      });
      for (int i = 0; i < need; i++) {
        if (row[i].sc) {
          cnt++;
        }
      }
      if (cnt == need) {
        ans++;
        for (int i = 0; i < need; i++) {
          c[row[i].fr][j] = '-';
          row[i].sc--;
        }
      } else {
        break;
      }
  
      while (!row.empty() && row.back().sc == 0) {
        row.pop_back();
      }
    }
  }
  
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      putchar(c[i][j]);
    }printf("\n");
  }
}
  
main() {
  cin >> tests;
  while (tests--) {
    solve();
  }
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:45:37: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |       if (col.empty() || col.size() < need) {
      |                          ~~~~~~~~~~~^~~~~~
stones.cpp:87:37: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |       if (row.empty() || row.size() < need) {
      |                          ~~~~~~~~~~~^~~~~~
stones.cpp: At global scope:
stones.cpp:124:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  124 | main() {
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1400 KB Output is correct
2 Correct 25 ms 2048 KB Output is correct
3 Correct 26 ms 2084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1536 KB Output is correct
2 Correct 23 ms 1912 KB Output is correct
3 Correct 21 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 29 ms 1400 KB Output is correct
6 Correct 25 ms 2048 KB Output is correct
7 Correct 26 ms 2084 KB Output is correct
8 Correct 25 ms 1536 KB Output is correct
9 Correct 23 ms 1912 KB Output is correct
10 Correct 21 ms 1664 KB Output is correct
11 Correct 10 ms 640 KB Output is correct
12 Correct 22 ms 1920 KB Output is correct
13 Correct 25 ms 2048 KB Output is correct
14 Correct 21 ms 1664 KB Output is correct
15 Correct 28 ms 2296 KB Output is correct
16 Correct 21 ms 1920 KB Output is correct
17 Correct 10 ms 1280 KB Output is correct