Submission #648322

#TimeUsernameProblemLanguageResultExecution timeMemory
648322ghostwriterRed-blue table (IZhO19_stones)C++14
100 / 100
31 ms2292 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #else #define debug(...) #endif #define ft front #define bk back #define st first #define nd second #define ins insert #define ers erase #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define bg begin #define ed end #define all(x) (x).bg(), (x).ed() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i)) #define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Tran The Bao - ghostwriter Training for VOI23 gold medal ---------------------------------------------------------------- DIT ME CHUYEN BAO LOC ---------------------------------------------------------------- */ const int N = 1001; int t, n, m; char a[N][N]; pi rs; void solve() { rs = {0, 0}; cin >> n >> m; FOR(i, 0, n) { int rm = (n - i) * (m - m / 2 - 1), need = max(0, n / 2 + 1 - i); if (!need) rs = max(rs, {n - i + m, i}); else rs = max(rs, {n - i + min(m, rm / need), i}); } FOR(i, 1, rs.nd) FOR(j, 1, m) a[i][j] = '-'; int rm = (n - rs.nd) * (m - m / 2 - 1), need = max(0, n / 2 + 1 - rs.nd); if (!need) { FOR(i, rs.nd + 1, n) FOR(j, 1, m) a[i][j] = (j <= m / 2 + 1? '+' : '-'); } else { int pos = rs.nd + 1; FOR(i, 1, m) { if (rm < need) continue; FOR(j, 1, need) { a[pos][i] = '-'; ++pos; if (pos > n) pos = rs.nd + 1; } rm -= need; } } FOR(i, 1, n) FOR(j, 1, m) if (!a[i][j]) a[i][j] = '+'; cout << rs.st << '\n'; FOR(i, 1, n) { FOR(j, 1, m) { cout << a[i][j]; a[i][j] = 0; } cout << '\n'; } } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> t; WHILE(t--) solve(); return 0; } /* ---------------------------------------------------------------- From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH ---------------------------------------------------------------- */

Compilation message (stderr)

stones.cpp: In function 'void solve()':
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:58:2: note: in expansion of macro 'FOR'
   58 |  FOR(i, 0, n) {
      |  ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:63:2: note: in expansion of macro 'FOR'
   63 |  FOR(i, 1, rs.nd)
      |  ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:64:2: note: in expansion of macro 'FOR'
   64 |  FOR(j, 1, m)
      |  ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:68:3: note: in expansion of macro 'FOR'
   68 |   FOR(i, rs.nd + 1, n)
      |   ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:69:3: note: in expansion of macro 'FOR'
   69 |   FOR(j, 1, m)
      |   ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:74:3: note: in expansion of macro 'FOR'
   74 |   FOR(i, 1, m) {
      |   ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:76:4: note: in expansion of macro 'FOR'
   76 |    FOR(j, 1, need) {
      |    ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:84:2: note: in expansion of macro 'FOR'
   84 |  FOR(i, 1, n)
      |  ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:85:2: note: in expansion of macro 'FOR'
   85 |  FOR(j, 1, m)
      |  ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:89:2: note: in expansion of macro 'FOR'
   89 |  FOR(i, 1, n) {
      |  ^~~
stones.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
stones.cpp:90:3: note: in expansion of macro 'FOR'
   90 |   FOR(j, 1, m) {
      |   ^~~
#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...