QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#784951#9802. Light Up the GridDoubeecatWA 21ms4408kbC++142.5kb2024-11-26 16:25:362024-11-29 22:55:27

Judging History

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

  • [2024-11-29 22:55:27]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:21ms
  • 内存:4408kb
  • [2024-11-26 16:25:37]
  • 评测
  • 测评结果:0
  • 用时:18ms
  • 内存:4580kb
  • [2024-11-26 16:25:36]
  • 提交

answer

/*
Undo the destiny.
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair

const int N = 1e5 + 10;

ll dp[N],a[4];
int bt[4] = {1,2,4,8};
bool flag;

void dfs(int sta,int now,ll dis) {
    int nsta;
    //cout << sta << " " << now << " " << dis << "\n";
    if (dis >= dp[sta]) {
        return ;
    }
    if (flag) dp[sta] = min(dp[sta],dis);
    flag = 1;
    for (int i = 0;i < 4;++i) {
        now ^= bt[i];
        nsta = sta | (1 << now);
        dfs(nsta,now,dis + a[0]);
        now ^= bt[i];
    }

    now ^= bt[0],now ^= bt[1];
    nsta = sta | (1 << now);
    dfs(nsta,now,dis + a[1]);
    now ^= bt[0],now ^= bt[1];

    
    now ^= bt[2],now ^= bt[3];
    nsta = sta | (1 << now);
    dfs(nsta,now,dis + a[1]);
    now ^= bt[2],now ^= bt[3];

    now ^= bt[0],now ^= bt[2];
    nsta = sta | (1 << now);
    dfs(nsta,now,dis + a[2]);
    now ^= bt[0],now ^= bt[2];

    
    now ^= bt[1],now ^= bt[3];
    nsta = sta | (1 << now);
    dfs(nsta,now,dis + a[2]);
    now ^= bt[1],now ^= bt[3];

    for (int i = 0;i < 4;++i) {
        now ^= bt[i];
    }
    nsta = sta | (1 << now);
    dfs(nsta,now,dis + a[3]);
}

void solve() {
    int n;cin >> n;
    int sta = 0;
    for (int i = 1;i <= n;++i) {
        string l = "";
        for (int i = 1;i <= 2;++i) {
            string s;cin >> s;
            l += s;
        }
        int now = 0;
        for (int i = 0;i < 4;++i) {
            now = now * 2 + (l[i] - '0');
        }
        sta |= (1 << now);
        //cout << now << "\n";
        //cout <<(1 << now) << "\n";
    }
    //cout << n << " " << sta << "\n";
    if (n == 1 && sta == 32768){
        cout << min(min(a[0],a[1]),min(a[2],a[3]))  * 2 << "\n";
        return ;
    }
    cout << dp[sta] << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);//cout.tie(0);
    int T;cin >> T;
    for (int i = 0;i < 4;++i) cin >> a[i];
    memset(dp,0x3f,sizeof dp);
    dfs(0,15,0);
    for (int i = (1 << 15) - 1;i >= 0;--i) {
        for (int j = 0;j < 15;++j) {
            if (i >> j & 1) {
                int nxt = i ^ (1 << j);
                dp[nxt] = min(dp[nxt],dp[i]);
            }
        }
    }
    while (T--) solve();
    return 0;
}
/*
2 1000 100 10 1
4
10
00

01
00

00
10

00
01

1
11
11
*/

详细

Test #1:

score: 100
Accepted
time: 21ms
memory: 4288kb

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: 4ms
memory: 4408kb

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: 0
Accepted
time: 4ms
memory: 4336kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 17ms
memory: 4404kb

input:

10000 8 2 7 8
8
00
01

00
11

00
10

11
11

10
10

01
10

01
00

10
11
8
11
01

11
00

01
10

11
11

00
01

01
01

01
00

11
10
9
00
00

01
01

10
11

00
01

11
10

11
00

11
11

00
11

01
10
9
11
11

10
00

11
00

11
01

00
10

01
11

00
01

01
01

10
01
11
00
01

01
01

10
10

00
11

11
11

11
10
...

output:

38
32
39
39
45
37
42
38
40
46
40
44
34
38
37
32
29
47
39
40
38
39
51
41
32
41
45
38
35
34
32
55
34
36
46
46
57
34
38
34
29
36
53
48
46
36
48
38
38
44
60
30
44
41
36
46
44
53
41
38
51
39
46
33
34
38
56
42
42
40
34
44
29
34
32
41
36
39
47
37
44
38
43
38
34
34
49
41
48
39
40
46
37
49
50
33
36
40
36
35
...

result:

wrong answer 1st numbers differ - expected: '34', found: '38'