QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691261#2943. NeighborsnickbelovTL 61ms3848kbC++203.5kb2024-10-31 10:37:172024-10-31 10:37:18

Judging History

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

  • [2024-10-31 10:37:18]
  • 评测
  • 测评结果:TL
  • 用时:61ms
  • 内存:3848kb
  • [2024-10-31 10:37:17]
  • 提交

answer

#include <vector>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define F(i, k) for(int16_t i = 0; i < (k); ++i)
#define G(x) int16_t x; cin >> x;
#define D for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) cout << gr[i][j] << " \n"[j == m];
#define MT(r, c, i) (!i ? r : c)
#define N 15
#define M 2

int16_t n = -1, m = -1;
int16_t gr[N][N], mk[M][N];int8_t du[N][N], dl[N][N];
int16_t tbl[N][3];

#define ADD(r, c, x) { gr[r][c] ^= x; F(i, M) mk[i][MT(r, c, i)] ^= 1 << x; }

bool bT(int16_t r, int16_t c) {
    if(r > n) return true;
    int16_t rI = r + (c == m), cI = c % m + 1;
    if(gr[r][c]) return bT(rI, cI);
    int16_t mask = mk[0][r] & mk[1][c]
        & tbl[gr[r - 1][c]][du[r][c]] & tbl[gr[r][c - 1]][dl[r][c]]
        & tbl[gr[r + 1][c]][du[r + 1][c]] & tbl[gr[r][c + 1]][dl[r][c + 1]];
    for(int16_t x = __builtin_ctzll(mask); mask >> x; ++x) if((mask >> x) & 1) {
        ADD(r, c, x);
        if(bT(rI, cI)) return true;
        ADD(r, c, x);
    }
    return false;
}
vector<pair<int,int>> ord;
bool bT(int idx) {
    if(idx >= n*m) return true;
    auto [r,c] = ord[idx];
    // cout << r << " " << c << endl;
    // cout << "\t" << idx << endl;
    if(gr[r][c]) return bT(idx+1);
    int16_t mask = mk[0][r] & mk[1][c]
        & tbl[gr[r - 1][c]][du[r][c]] & tbl[gr[r][c - 1]][dl[r][c]]
        & tbl[gr[r + 1][c]][du[r + 1][c]] & tbl[gr[r][c + 1]][dl[r][c + 1]];
    for(int16_t x = __builtin_ctzll(mask); mask >> x; ++x) if((mask >> x) & 1) {
        ADD(r, c, x);
        if(bT(idx+1)) return true;
        ADD(r, c, x);
    }
    return false;
}

void init() {
    cin >> n; G(k) m = n;
    fill_n(tbl[0], 3, (1 << 15) - 1);
    F(i, n + 1) if(i) {
        tbl[i][0] = (1 << 15) - 1; //no constraint
        tbl[i][2] = 5 << (i - 1); //diamond
        tbl[i][1] = ~tbl[i][2]; //no diamond
    }
    F(q, 2 * n - 1) if(q & 1) {
        int16_t r = (q + 1) / 2;
        string s; cin >> s;
        F(i, n) du[r + 1][i + 1] = 1 + (s[i] == '1');
    } else {
        int16_t r = q / 2;
        string s; cin >> s;
        F(i, n) if(i) dl[r + 1][i + 1] = 1 + (s[i - 1] == '1');
    }
    F(i, M) fill_n(mk[i], N, (1 << (n + 1)) - 2);
    queue<pair<int,int>> q;
    while(k--) {
        G(r) G(c) G(v)
        ADD(r, c, v);
        q.emplace(r,c);
    }
    #define K first 
    #define V second
    vector<vector<bool>> done(n+1,vector<bool>(m+1));
    int rnum = 1,cnum=1;
    while(rnum<=n or cnum<=m){
        if(cnum>m){
            for(int j = 1;j<=m;j++) if(!done[rnum][j]) ord.emplace_back(rnum,j),done[rnum][j]=1;
            rnum++;
        }
        else if(rnum>n){
            for(int i = 1;i<=n;i++) if(!done[i][cnum]) ord.emplace_back(i,cnum),done[i][cnum]=1;
            cnum++;
        }
        else if(rnum<=cnum){
            for(int j = 1;j<=m;j++) if(!done[rnum][j]) ord.emplace_back(rnum,j),done[rnum][j]=1;
            rnum++;
        }
        else{
            for(int i = 1;i<=n;i++) if(!done[i][cnum]) ord.emplace_back(i,cnum),done[i][cnum]=1;
            cnum++;
        }
    }
    // ranges::sort(ord,[&](pair<int,int> p1,pair<int,int> p2){return p1.K-p1.V < p2.K-p2.V;});
    // mt19937 gen(__builtin_ia32_rdtsc());
    // ranges::shuffle(ord,gen);
}

int main() {
    clock_t t = clock();
    init(); bT(0); D
    // cout << (clock() - t) / (double)(CLOCKS_PER_SEC) << '\n';
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

input:

7 6
100000
0111010
100000
0000000
001001
0010010
000000
0000000
000000
0000000
001000
0001010
000001
2 7 7
6 1 2
3 3 2
7 6 2
5 3 6
4 7 6

output:

4 3 5 7 1 6 2
1 2 4 6 3 5 7
7 5 2 1 6 3 4
3 7 1 5 2 4 6
5 1 6 2 4 7 3
2 6 3 4 7 1 5
6 4 7 3 5 2 1

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

7 6
100011
0010000
000001
1101010
010010
0111100
010000
0001000
011011
0001000
010101
0100000
000010
4 3 2
4 5 7
1 2 6
5 4 5
2 4 2
5 1 1

output:

5 6 4 7 1 2 3
3 1 5 2 4 6 7
4 2 1 3 6 7 5
6 3 2 4 7 5 1
1 7 6 5 2 3 4
7 4 3 6 5 1 2
2 5 7 1 3 4 6

result:

ok 7 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

8 9
0001000
10110100
1000000
00001110
0001001
10100011
0000101
00000100
0101001
10000000
0000000
00100101
0010001
00100000
0000010
3 5 3
4 1 7
6 8 6
4 5 1
1 4 7
1 3 5
1 5 6
3 6 6
6 2 8

output:

4 2 5 7 6 8 1 3
5 6 4 8 2 7 3 1
8 1 7 2 3 6 4 5
7 3 8 6 1 2 5 4
2 5 6 3 4 1 7 8
1 8 3 5 7 4 2 6
6 4 2 1 5 3 8 7
3 7 1 4 8 5 6 2

result:

ok 8 lines

Test #4:

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

input:

9 9
00000100
010001001
01010010
010000010
00100101
100000010
10100010
010000100
01000001
100000000
00000000
010100000
10010100
000010100
00101000
110100000
00001000
3 5 6
4 2 1
7 1 4
2 2 6
6 9 1
5 7 4
3 1 1
4 3 5
9 4 4

output:

3 5 2 7 1 9 8 6 4
9 6 7 3 4 8 1 2 5
1 7 9 8 6 4 5 3 2
2 1 5 6 9 7 3 4 8
8 2 3 9 5 1 4 7 6
7 4 6 2 8 3 9 5 1
4 3 8 1 2 5 6 9 7
6 8 4 5 3 2 7 1 9
5 9 1 4 7 6 2 8 3

result:

ok 9 lines

Test #5:

score: 0
Accepted
time: 61ms
memory: 3848kb

input:

10 11
010000000
1000000000
010101011
0101000001
001001000
0100100000
101000000
0000000001
000001000
0000101010
000000000
0000000001
100000000
0001000000
000001001
1000110000
100000011
1100000011
111010101
5 8 3
9 1 7
3 8 4
3 4 3
10 6 9
4 9 2
6 3 4
2 3 5
1 2 2
8 4 9
2 5 1

output:

9 2 3 8 4 6 10 7 1 5
10 6 5 2 1 4 3 9 8 7
1 5 2 3 9 7 8 4 10 6
3 4 7 6 8 1 5 10 2 9
5 1 9 4 2 8 7 3 6 10
2 9 4 7 3 10 6 8 5 1
4 3 8 10 7 5 1 6 9 2
6 10 1 9 5 3 4 2 7 8
7 8 10 1 6 2 9 5 4 3
8 7 6 5 10 9 2 1 3 4

result:

ok 10 lines

Test #6:

score: -100
Time Limit Exceeded

input:

11 12
0000001101
00000001000
0011000000
00110000000
0010000010
00000110000
0000100000
00000001100
0000000000
01010000010
0000010000
00001010000
0000000101
00000010010
0100100000
00100000101
1000010100
00100001010
1001000000
00010001000
0000000000
8 7 7
8 9 1
10 11 9
6 5 10
9 2 8
1 10 8
4 6 6
2 4 10
...

output:


result: