QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#781339#9802. Light Up the GridIGVATL 2ms11988kbC++141.8kb2024-11-25 15:46:142024-11-25 15:46:15

Judging History

你现在查看的是测评时间为 2024-11-25 15:46:15 的历史记录

  • [2024-11-29 22:52:10]
  • 管理员手动重测本题所有提交记录
  • 测评结果:TL
  • 用时:1ms
  • 内存:12284kb
  • [2024-11-25 15:46:15]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:11988kb
  • [2024-11-25 15:46:14]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define dep(i,a,b) for(int i=(a),i##_end=(b);i>=i##_end;--i)
using namespace std;
template<class T>inline T mymin(T x,T y){return x<y?x:y;}
template<class T>inline T mymax(T x,T y){return x>y?x:y;}
template <typename T>
inline void read(T &X){
    X=0;int w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=X*10+(ch^48),ch=getchar();
    if(w) X=-X;
}
const int maxn = 4e5 + 5;
//const double pi = acos(-1.0);
//const double eps = 1e-9;
//const int mo = 1e9 + 7;
int n,m,k;
int a[maxn],c[maxn],d[maxn];
int ans,tmp,cnt;
int flag;
char s[10][10];
bool ok[maxn][16];
int dp[maxn][16];
int jh[] = {1,2,4,8,3,12,5,10,15};
int w[] = {0,0,0,0,1,1,2,2,3};
queue<pair<int,int>>q;
void solve(){
	read(n);
	m = (1 << n) - 1;
	rep(i,0,15) d[i] = 0;
	rep(i,0,n - 1){
		rep(j,0,1){
			scanf("%s",s[j]);
		}
		c[i] = (s[0][0] & 1) | ((s[0][1] & 1) << 1) | ((s[1][0] & 1) << 2) | ((s[1][1] & 1) << 3);
		c[i] ^= 15;
		d[c[i]] ^= (1 << i);
	}
	rep(i,0,m) rep(j,0,15) {
		dp[i][j] = inf;
		ok[i][j] = 0;
	}
	dp[m][0] = 0;
	ok[n][0] = 1;
	q.push({m,0});
	while(!q.empty()){
		auto nd = q.front();q.pop();
		int i = nd.first;
		int j = nd.second;
		rep(l,0,8){
			int nj = j ^ jh[l];
			int ni = i ^ (i & d[nj]);
			if(dp[i][j] + a[w[l]] < dp[ni][nj]){
				dp[ni][nj] = dp[i][j] + a[w[l]];
				if(!ok[ni][nj]) {
					q.push({ni,nj});
					ok[ni][nj] = 1;
				}
			}
		}
	}
	int ans = inf;
	rep(i,0,15) ans = min(ans,dp[0][i]);
	printf("%d\n",ans);
}
int main(){
    //cin.tie(0)->sync_with_stdio(false);
    int T=1,cas=1;
    read(T);
	rep(i,0,3) read(a[i]);
    while(T--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11956kb

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

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

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Time Limit Exceeded

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
37
37
32
29
40
39
40
38
39
44
37
29
37
37
38
34
34
32
41
34
36
41
40
44
34
37
34
29
36
39
40
42
35
39
37
38
39
41
29
40
41
36
41
43
44
41
34
42
39
37
33
34
38
38
37
42
40
34
36
28
34
32
38
36
39
38
37
36
38
34
34
34
34
42
40
38
38
40
40
37
40
38
29
36
40
36
34
...

result: