QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#785306#9802. Light Up the GridMENDAXWA 22ms11464kbC++202.4kb2024-11-26 17:27:592024-11-26 17:28:04

Judging History

你现在查看的是测评时间为 2024-11-26 17:28:04 的历史记录

  • [2024-11-29 22:55:41]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:23ms
  • 内存:11672kb
  • [2024-11-26 17:28:04]
  • 评测
  • 测评结果:0
  • 用时:22ms
  • 内存:11464kb
  • [2024-11-26 17:27:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int 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 = 1e6 + 10;

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

/*
2 1000 100 10 1
4
10
00
01
00
00
10
00
01
1
11
11
*/

void dfs(int sta,int now,int dis) {
    int nsta;
    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]);
}

int cnt;

string ge(int p){
	string s="";
	for(int i=0;i<16;i++){
		if(p>>i&1)s="1"+s;
		else s="0"+s;
	}
	return s;
}

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);
    }
    cnt++;
    if(cnt==6){
    	cout<<ge(sta)<<endl;
	}
    else 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 << 16) - 1;i >= 0;--i) {
        for (int j = 0;j < 16;++j) {
            if (i >> j & 1) {
                int nxt = i - (1 << j);
                dp[nxt] = min(dp[nxt],dp[i]);
            }
        }
    }
    while (T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 22ms
memory: 11424kb

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

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: 6ms
memory: 11356kb

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: 11368kb

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:

34
32
36
36
40
0110110111110010
42
38
40
41
36
44
34
38
37
32
29
40
39
40
38
39
44
37
31
38
37
38
35
34
32
41
34
36
42
40
44
34
38
34
29
36
39
40
42
36
39
38
38
39
42
30
40
41
36
43
44
40
41
34
42
39
37
33
34
38
38
38
42
40
34
36
29
34
32
38
36
39
38
37
36
38
34
34
34
34
42
41
38
39
40
42
37
40
38
2...

result:

wrong output format Expected integer, but "0110110111110010" found