QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#785315#9802. Light Up the GridMENDAXWA 26ms11476kbC++202.4kb2024-11-26 17:29:222024-11-29 22:55:51

Judging History

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

  • [2024-11-29 22:55:51]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:26ms
  • 内存:11476kb
  • [2024-11-26 17:29:23]
  • 评测
  • 测评结果:0
  • 用时:26ms
  • 内存:11432kb
  • [2024-11-26 17:29:22]
  • 提交

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<<36<<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: 26ms
memory: 11436kb

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

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

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

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
36
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
29
36
40
36
35
...

result:

wrong answer 14th numbers differ - expected: '37', found: '38'