QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#784562#9802. Light Up the GridF9O1#WA 35ms18188kbC++203.6kb2024-11-26 15:21:262024-11-26 15:21:26

Judging History

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

  • [2024-11-26 15:21:26]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:18188kb
  • [2024-11-26 15:21:26]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define pii std::pair<int, int>
#define NL std::cout << '\n'

const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18;
const double eps = 1e-8;

int head[maxn << 1], e[maxn << 1], en[maxn << 1], idx = 2;
int val[maxn << 1];

void add(int u, int v) {
    e[idx] = v;
    en[idx] = head[u];
    // val[idx] = w;
    head[u] = idx++;
}


int a0,a1,a2,a3;
int a[maxn];
int nx[] = {0,0,1,-1};
int ny[] = {1,-1,0,0};

void solve() {
    int t; std::cin >> t;
    std::cin >> a0 >> a1 >> a2 >> a3;
    std::vector<int> d(20);
    std::vector<std::vector<int> > gr(2,std::vector<int>(2));
    int cur = inf;
    std::function<void(int)> dfs = [&](int x) {
        bool ch = true;
        for(int i = 0; i < 2; ++i) {
            for(int j = 0; j < 2; ++j) {
                if(gr[i][j] == 0) ch = false;
            }
        }
        if(ch && x) {
            cur = std::min(cur,x);
            return;
        }
        if(x > 4) return;
        for(int i = 0; i < 2; ++i) {
            gr[i][1] ^= 1; gr[i][0] ^= 1;
            dfs(x+a1);
            gr[i][1] ^= 1; gr[i][0] ^= 1;
        }
        for(int i = 0; i < 2; ++i) {
            gr[0][i] ^= 1; gr[1][i] ^= 1;
            dfs(x+a2);
            gr[0][i] ^= 1; gr[1][i] ^= 1;
        }
        for(int i = 0; i < 2; ++i) {
            for(int j = 0; j < 2; ++j) {
                gr[i][j] ^= 1;
                dfs(x+a0);
                gr[i][j] ^= 1;
            }
        }
        for(int i = 0; i < 2; ++i) {
            for(int j = 0; j < 2; ++j) {
                gr[i][j] ^= 1;
            }
        }
        dfs(x+a3);
        for(int i = 0; i < 2; ++i) {
            for(int j = 0; j < 2; ++j) {
                gr[i][j] ^= 1;
            }
        }
    };
    for(int i = 0; i < 16; ++i) {
        cur = inf;
        int temp = i;
        std::vector<int> q;
        for(int j = 0; j < 4; ++j) q.push_back(temp % 2), temp >>= 1;
        for(int j = 0; j < 2; ++j) {
            for(int k = 0; k < 2; ++k) {
                gr[j][k] = q.back();
                q.pop_back();
            }
        }
        dfs(0);
        d[i] = cur;
    }
    std::vector<std::vector<int> > f(1ll << 16,std::vector<int>(20,inf));
    for(int i = 0 ; i < 16; ++i) f[(1ll << i)][i] = d[i];
    for(int i = 1; i < (1ll << 16); ++i) {
        for(int j = 0; j < 16; ++j) {
            if(i & (1ll << j)) {
                int fom = (i ^ (1ll << j));
                for(int k = 0; k < 16; ++k) {
                    if(fom & (1ll << k)) {
                        // if(i == 3 && j == 0) std::cout << fom << ' ' << (j^(15^k)) << '\n';
                        f[i][j] = std::min(f[i][j],f[fom][k] + d[(j^(15^k))]);
                    }
                }
            }
        }
    }
    while(t--) {
        int m; std::cin >> m;
        int state = 0;
        for(int p = 0; p < m; ++p) {
            int now = 0;
            for(int i = 0; i < 2; ++i) {
                for(int j = 0; j < 2; ++j) {
                    char x; std::cin >> x;
                    now = (now << 1) + x - '0';
                }
            }
            state += (1ll << now);
        }
        int ans = inf;
        for(int i = 0; i < 16; ++i) {
            if(state & (1ll << i)) {
                ans = std::min(ans,f[state][i]);
            }
        }
        std::cout << ans; NL;
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);
    int T = 1;
    // std::cin >> T;
    while (T--) {
        solve(); NL;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 30ms
memory: 18188kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2


result:

ok 2 number(s): "1121 2"

Test #2:

score: 0
Accepted
time: 35ms
memory: 18020kb

input:

2 1 1 1 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

5
2


result:

ok 2 number(s): "5 2"

Test #3:

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

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

1000000000000000000


result:

wrong answer 1st numbers differ - expected: '2000000', found: '1000000000000000000'