QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99464#6309. Aqrergnerdplayer#WA 29ms3476kbC++205.7kb2023-04-22 17:07:182023-04-22 17:07:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-22 17:07:20]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:3476kb
  • [2023-04-22 17:07:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/priority_queue.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
/* ordered_set notes:
    .order_of_key(k): Number of items strictly smaller than k
    .find_by_order(k): k-th element in a set
*/
#define X first
#define Y second
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.X << ", " << a.Y << ')';
}
#ifdef cychien
#define DE(...) do {\
	fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
    _DO(__VA_ARGS__);\
}while(0) 
template<typename I> void _DO(I&&x) {cerr << x << '\n';}
template<typename I, typename ...T> void _DO(I&&x,T&&...tail) {cerr << x << ", "; _DO(tail...);}
#define IOS
#define debug(v) {cerr << #v << " = ["; for(auto it = (v).begin(); it != (v).end(); it++){cerr << *it; if (next(it) != (v).end()) cerr << ", "; } cerr << "]\n";}
#else
#define DE(...)
#define debug(v)  
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#endif
#define W(v) {for(auto it = (v).begin(); it != (v).end(); it++)cout << *it << " \n"[next(it) == (v).end()];}
#define pb emplace_back
#define mp make_pair
#define rsz resize
#define SZ(x) (ll)x.size()
#define AI(x) (x).begin(),(x).end()
#define SORT(x) sort(AI(x))
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
const int NF = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Rand(){
    return uniform_int_distribution<int>(INT_MIN, INT_MAX)(rng);
}
/*
#include <atcoder/all>
using namespace atcoder;
*/

/* LazySegtree

// Example for range linear transfromation & range sum
// Monoid Property: op(F(a), F(b)) == F(op(a, b))
// Declaration: lazy_segtree<S, op, e, F, mapping, composition, id> seg(n);

struct S { // Node
    mint sum;
    int len;
};
S op(S x, S y){ // pull
    return S{x.sum + y.sum, x.len + y.len};
}
S e(){ // e s.t. op(x, e) == x
    return S{0, 1};
}
 
struct F {
    mint a, b;
};
S mapping(F t, S x){ // push
    return S{t.a * x.sum + t.b * x.len, x.len};
}
F composition(F f, F g){ // f o g
    return F{f.a * g.a, f.a * g.b + f.b};
}
F id() { // id s.t. composition(F, id) == F
    return F{1, 0};
}

*/
void solve(){
    int n, m; cin >> n >> m;
    string ans;
    if (n <= 3 && m <= 3){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                ans += '1';
            }
            ans += '\n';
        }
    }
    else if (n == 1){
        for (int j = 0; j < m; j++){
            ans += "01"[j < 3];
        }
        ans += '\n';
    }
    else if (m == 1){
        for (int i = 0; i < n; i++){
            ans += "01"[i < 3];
            ans += '\n';
        }
    }
    else {
        vector<string> pat = {"1110", "1011", "1101", "0111"};
        function<bool(int, int)> valid = [&](int x, int y){
            return x >= 0 && x < n && y >= 0 && y < m;
        };
        function<bool(vector<vector<char>>&)> connected = [&](vector<vector<char>>& v){
            int tot = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    tot += (v[i][j] == '1');

            vector<pii> d = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
            for (int i = 0; i < n; i++){
                for (int j = 0; j < m; j++){
                    if (v[i][j] == '1'){
                        vector<vector<bool>> vis(n, vector<bool>(m));
                        int cnt = 0;
                        queue<pii> q;
                        q.push(mp(i, j));
                        vis[i][j] = 1;
                        while (!q.empty()){
                            ++cnt;
                            auto [x, y] = q.front(); q.pop();
                            for (int b = 0; b < 4; b++){
                                auto [dx, dy] = d[b];
                                if (valid(x + dx, y + dy) && !vis[x + dx][y + dy] && v[x + dx][y + dy] == '1'){
                                    q.push(mp(x + dx, y + dy));
                                    vis[x + dx][y + dy] = 1;
                                }
                            }
                        }
                        return cnt == tot;
                    }
                }
            }

            return true;
        };
        for (int s = 0; s < 4; s++){
            for (int h = 0; h < 4; h++){
                string tmp;
                vector<vector<char>> v(n, vector<char>(m));
                for (int i = 0; i < n; i++){
                    for (int j = 0; j < m; j++){
                        tmp += pat[(i + s) % 4][(j + h) % 4];
                        v[i][j] = pat[(i + s) % 4][(j + h) % 4];
                    }
                    tmp += '\n';
                }
                if (connected(v) && count(AI(tmp), '1') > count(AI(ans), '1')){
                    ans = tmp;
                }
            }
        }
    }
    cout << count(AI(ans), '1') << '\n' << ans;
}
int main() {
    IOS;
    int T; cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3412kb

input:

3
2 2
3 4
3 8

output:

4
11
11
9
1110
1011
1101
18
11101110
10111011
11011101

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 29ms
memory: 3476kb

input:

361
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
2 20
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
3 16
3 17
3 18
3 19
3 20
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
4 15
4 16
4 17
4 18
4 19
4 20
5 2
5 3
5 4
5 5
5 6
5 7
5 8
5 9
5 1...

output:

4
11
11
6
111
111
6
1110
1011
8
11101
10111
9
111011
101110
11
1110111
1011101
12
11101110
10111011
14
111011101
101110111
15
1110111011
1011101110
17
11101110111
10111011101
18
111011101110
101110111011
20
1110111011101
1011101110111
21
11101110111011
10111011101110
23
111011101110111
1011101110111...

result:

wrong answer ans finds a larger answer (test case 25)