QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#831333#7714. Rikka with MirrorfryanAC ✓42ms11844kbC++202.3kb2024-12-25 13:40:522024-12-25 13:40:52

Judging History

This is the latest submission verdict.

  • [2024-12-25 13:40:52]
  • Judged
  • Verdict: AC
  • Time: 42ms
  • Memory: 11844kb
  • [2024-12-25 13:40:52]
  • Submitted

answer

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

const int mxn = 8;
const int inf = 1e9;

void ckmax(int &a, int b) {
	a = max(a,b);
}

int n,m,g[mxn][mxn];
int dp[mxn][mxn][1<<mxn][2][mxn*mxn];

void solve() {
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			char c; cin>>c;
			g[i][j] = c-'0';
		}
	}
	dp[0][0][0][0][0] = 0;
	if (g[0][0]) {dp[0][0][1][1][1] = 2;}
	for (int x=0; x<n; x++) {
		for (int y=1; y<m; y++) {
			for (int umk=0; umk<(1<<m); umk++) {
				for (int lr=0; lr<2; lr++) {
					for (int cnt=0; cnt<n*m; cnt++) {
						if (dp[x][y-1][umk][lr][cnt]==-1) continue;
						//case 1 - no mirror
						int av1 = 0;
						if (lr) av1++;
						if ((1<<y)&umk) av1++;
						ckmax(dp[x][y][umk][lr][cnt],dp[x][y-1][umk][lr][cnt]+av1);
						if (!g[x][y]) continue;
						//case 2 - /, no send
						if (lr && (umk&(1<<y))) {ckmax(dp[x][y][umk-(1<<y)][0][cnt+1],dp[x][y-1][umk][lr][cnt]);}
						//case 3 - /, send
						if ( lr&&(umk&(1<<y)) || (!lr)&&!(umk&(1<<y)) ) {
							ckmax(dp[x][y][umk|(1<<y)][1][cnt+1],dp[x][y-1][umk][lr][cnt]+2);
						}
						//case 4 - \, no send down
						if (!lr && (umk&(1<<y))) {ckmax(dp[x][y][umk-(1<<y)][1][cnt+1],dp[x][y-1][umk][lr][cnt]+1);}
						//case 5 - \, send down
						if (lr) {							
							ckmax(dp[x][y][umk|(1<<y)][(umk>>y)&1][cnt+1],dp[x][y-1][umk][lr][cnt]+1+((umk>>y)&1));
						}
					}
				}
			}
		}
		for (int umk=0; umk<(1<<m); umk++) {
			for (int cnt=0; cnt<n*m; cnt++) {
				//transition from dp[x][m-1][umk][0][cnt]
				//case 1 - no mirror
				if (dp[x][m-1][umk][0][cnt]==-1) continue;
				int av1 = 0;
				if (1&umk) av1++;
				ckmax(dp[x+1][0][umk][0][cnt],dp[x][m-1][umk][0][cnt]+av1);
				if (!g[x+1][0]) continue;
				//case 2 - mirror \`
				if (umk&1) {
					ckmax(dp[x+1][0][umk-1][1][cnt+1],dp[x][m-1][umk][0][cnt]+1);
				}
				//case 3 - mirror / '
				if (!(umk&1)) {
					ckmax(dp[x+1][0][umk+1][1][cnt+1],dp[x][m-1][umk][0][cnt]+2);
				}
			}
		}
	}
	
	int cv = 0;
	for (int i=0; i<=n*m; i++) {
		ckmax(cv,dp[n-1][m-1][0][0][i]);
		cout<<n*m*4-2*cv<<" ";
	}
	cout<<"\n";
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	int t; cin>>t;
	while (t--) solve();
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11844kb

input:

2
3 3
101
011
101
4 4
1111
1111
1111
1111

output:

36 36 36 36 20 20 20 20 20 20 
64 64 64 64 40 40 40 40 32 32 32 32 24 24 24 24 24 

result:

ok 27 numbers

Test #2:

score: 0
Accepted
time: 42ms
memory: 11788kb

input:

100
1 1
1
1 2
11
1 3
111
1 4
1111
1 5
11111
1 6
111111
1 7
1111111
2 1
1
1
2 2
11
11
2 3
111
111
2 4
1111
1111
2 5
11111
11111
2 6
111111
111111
2 7
1111111
1111111
3 1
1
1
1
3 2
11
11
11
3 3
111
111
111
3 4
1111
1111
1111
3 5
11111
11111
11111
3 6
111111
111111
111111
3 7
1111111
1111111
1111111
4 ...

output:

4 4 
8 8 8 
12 12 12 12 
16 16 16 16 16 
20 20 20 20 20 20 
24 24 24 24 24 24 24 
28 28 28 28 28 28 28 28 
8 8 8 
16 16 16 16 8 
24 24 24 24 12 12 12 
32 32 32 32 16 16 16 16 16 
40 40 40 40 20 20 20 20 20 20 20 
48 48 48 48 24 24 24 24 24 24 24 24 24 
56 56 56 56 28 28 28 28 28 28 28 28 28 28 28 
1...

result:

ok 2411 numbers