QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#321034#8217. King's Dinnerucup-team008#AC ✓2ms3860kbC++175.9kb2024-02-04 02:31:452024-02-04 02:31:45

Judging History

你现在查看的是最新测评结果

  • [2024-02-04 02:31:45]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3860kb
  • [2024-02-04 02:31:45]
  • 提交

answer

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_set>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(1) cerr

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD

template<class Fun>
class y_combinator_result {
  Fun fun_;
public:
  template<class T>
  explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

  template<class ...Args>
  decltype(auto) operator()(Args &&...args) {
    return fun_(std::ref(*this), std::forward<Args>(args)...);
  }
};

template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
  return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

template<class T>
bool updmin(T& a, T b) {
  if(b < a) {
    a = b;
    return true;
  }
  return false;
}
template<class T>
bool updmax(T& a, T b) {
  if(b > a) {
    a = b;
    return true;
  }
  return false;
}
typedef int64_t ll;

vector<array<int, 4>> gen(int n) {
  if(n <= 2) {
    vector<array<int, 4>> ret;
    return ret;
  }
  if(n > 7) {
    vector<array<int, 4>> ret = gen(n-6);
    // shift col right by n-6
    {
      int crow = 0;
      int cmax = n-6;
      while(crow + 2 <= cmax) {
        if(crow + 3 <= cmax && crow % 2 != cmax%2) {
          ret.pb({crow, n-6, 3, 2});
          ret.pb({crow, n-4, 3, 2});
          ret.pb({crow, n-2, 3, 2});
          crow += 3;
        }
        else {
          ret.pb({crow, n-6, 2, 3});
          ret.pb({crow, n-3, 2, 3});
          crow += 2;
        }
      }
    }
    // shift row down by n-6
    {
      int ccol = 0;
      int cmax = n-6;
      while(ccol + 2 <= cmax) {
        if(ccol + 3 <= cmax && ccol % 2 != cmax%2) {
          ret.pb({n-6, ccol, 2, 3});
          ret.pb({n-4, ccol, 2, 3});
          ret.pb({n-2, ccol, 2, 3});
          ccol += 3;
        }
        else {
          ret.pb({n-6, ccol, 3, 2});
          ret.pb({n-3, ccol, 3, 2});
          ccol += 2;
        }
      }
    }
    // 6 by 6
    {
      ret.pb({n-6, n-6, 3, 2});
      ret.pb({n-6, n-4, 3, 2});
      ret.pb({n-6, n-2, 3, 2});
      ret.pb({n-3, n-6, 3, 2});
      ret.pb({n-3, n-4, 3, 2});
      ret.pb({n-3, n-2, 3, 2});
    }
    return ret;
  }
  assert(n <= 7);
  vector<array<int, 4>> ret;
  if(n == 3) {
    ret.pb({0, 0, 3, 2});
  }
  if(n == 4) {
    ret.pb({0, 0, 3, 2});
    ret.pb({0, 2, 3, 2});
  }
  if(n == 5) {
    ret.pb({0, 0, 3, 2});
    ret.pb({0, 2, 2, 3});
    ret.pb({2, 3, 3, 2});
    ret.pb({3, 0, 2, 3});
  }
  if(n == 6) {
    ret.pb({0, 0, 3, 2});
    ret.pb({0, 2, 3, 2});
    ret.pb({0, 4, 3, 2});
    ret.pb({3, 0, 3, 2});
    ret.pb({3, 2, 3, 2});
    ret.pb({3, 4, 3, 2});
  }
  if(n == 7) {
    ret.pb({0, 0, 3, 2});
    ret.pb({0, 2, 3, 2});
    ret.pb({0, 4, 2, 3});
    ret.pb({2, 4, 2, 3});
    ret.pb({3, 0, 2, 3});
    ret.pb({5, 0, 2, 3});
    ret.pb({4, 3, 3, 2});
    ret.pb({4, 5, 3, 2});
  }
  return ret;
}
void sanitycheck(int sz, const vector<array<int, 4>>& v) {
  for(int i = 0; i < sz(v); i++) {
    assert(v[i][0] >= 0 && v[i][0] + v[i][2] <= sz);
    assert(v[i][1] >= 0 && v[i][1] + v[i][3] <= sz);
  }
  for(int i = 0; i < sz(v); i++) for(int j = 0; j < i; j++) {
    bool avoided = false;
    if(v[j][0] >= v[i][0] + v[i][2]) avoided = true;
    if(v[i][0] >= v[j][0] + v[j][2]) avoided = true;
    if(v[j][1] >= v[i][1] + v[i][3]) avoided = true;
    if(v[i][1] >= v[j][1] + v[j][3]) avoided = true;
    assert(avoided);
  }
}
int slow(int n) {
  return ((n+1)*(n+1))/6;
}
void fast(int n) {
  vector<array<int, 4>> go = gen(n+1);
  /*
  int ans = slow(n);
  assert(ans == sz(go));
  sanitycheck(n+1, go);
  */
  vector<vector<char>> ret(n);
  for(auto& x: ret) x.assign(n, '.');
  for(auto [x, y, rlen, clen]: go) {
    ret[x][y] = '#';
    if(rlen == 3) ret[x+1][y] = '#';
    else {
      assert(clen == 3);
      ret[x][y+1] = '#';
    }
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      cout << ret[i][j];
    }
    cout << "\n";
  }
}
void solve() {
  int t;
  cin >> t;
  while(t--) {
    int n;
    cin >> n;
    fast(n);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3768kb

input:

3
1
2
3

output:

.
#.
#.
#.#
#.#
...

result:

ok all tests correct (3 test cases)

Test #2:

score: 0
Accepted
time: 1ms
memory: 3860kb

input:

50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

output:

.
#.
#.
#.#
#.#
...
#.##
#...
...#
##.#
#.#.#
#.#.#
.....
#.#.#
#.#.#
#.#.##
#.#...
....##
##....
...#.#
##.#.#
..##.##
.......
#.#.#.#
#.#.#.#
.......
#.#.#.#
#.#.#.#
#..#.#.#
#..#.#.#
........
##.#.#.#
...#.#.#
##......
...#.#.#
##.#.#.#
#.#.##.##
#.#......
....##.##
.........
#.#.#.#.#
#.#.#.#.#
...

result:

ok all tests correct (50 test cases)

Test #3:

score: 0
Accepted
time: 2ms
memory: 3616kb

input:

39
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

output:

#.#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##
#.#................................................
....##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##
...................................................
#.#.#.#.#.##.##.##.##.##.##.##.##.##.##.##.##.##.##
#.#.#.#.#..................................

result:

ok all tests correct (39 test cases)

Test #4:

score: 0
Accepted
time: 1ms
memory: 3676kb

input:

11
90
91
92
93
94
95
96
97
98
99
100

output:

#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
#.#....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
....##....................................................................................
##.....##.##.##.##.##.##.##...

result:

ok all tests correct (11 test cases)

Test #5:

score: 0
Accepted
time: 1ms
memory: 3808kb

input:

1
100

output:

#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
#....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
...#.................................................................................................

result:

ok all tests correct (1 test case)

Extra Test:

score: 0
Extra Test Passed