QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745609#4893. ImbalanceNineSuns20 1039ms394576kbC++143.7kb2024-11-14 10:47:402024-11-14 10:47:40

Judging History

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

  • [2024-11-14 10:47:40]
  • 评测
  • 测评结果:20
  • 用时:1039ms
  • 内存:394576kb
  • [2024-11-14 10:47:40]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back

using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 125, mod = 998244353; 
int n, k, m, s[5]; 
string str; 

namespace T1 {
	int mk[1<<22], f[1<<22], g[1<<22]; 
	void solve () {
		for (int i = 0;i < (1<<k);i++) mk[i] = __builtin_popcount(i) != (k/2); 
		int t = 0; for (int i = 0;i < m;i++) t = (t<<1)+(str[i]-'0'); 
		int ans = 0, S = (1<<k)-1; 
		for (int i = 0;i < (1<<k-m);i++) {
			if (mk[(t<<k-m)|i]) {
				f[(t<<k-m)|i] = 1; 
			}
		}
		for (int i = k;i < n;i++) {
			memset(g, 0, sizeof g); 
			for (int j = 0;j < (1<<k);j++) {
				if (!mk[j]) continue; 
				(g[S&(j<<1)] += f[j]) %= mod;
				(g[S&(j<<1|1)] += f[j]) %= mod;
			}
			swap(f, g); 
		}
		for (int i = 0;i < (1<<k);i++) if (mk[i]) (ans += f[i]) %= mod;
		cout << ans; 
	}
}

namespace T2 {
	int f[65][115][115][115], g[65][115][115], mk[N][N], sf[64], ans, sz, sv[7], dt[7][7]; 
	void init () {
		memset(f, 0, sizeof f); memset(g, 0, sizeof g); 
		for (int sn = 0;sn <= (k/2)*sz;sn++) {
			memset(mk, 0, sizeof mk); 
			int ts = (k/2)*(sz-1);
			for (int j = ts;j <= n;j++) mk[0][j]++;  
			for (int i = 0;i < m;i++) {
				ts += str[i]-'0'; 
				for (int j = ts;j <= n;j++) mk[i+1][j]++; 
			}
//			cout << "START:" << m << " " << ts << endl; 
			mk[m][ts]--; 
			for (int i = sn;i >= 0;i--) for (int j = n%k;j <= k;j++) mk[j][i]++; 
			mk[n%k][sn]--; 
//			cout << "END:" << sn << " " << mk[n%k][sn] << endl ; 
			if (!mk[m][ts]) {
				g[sn][m][ts] = 1;
				for (int i = m;i < k;i++) {
					for (int j = ts;j <= n;j++) {
						if (!mk[i+1][j]) (g[sn][i+1][j] += g[sn][i][j]) %= mod; 
						if (!mk[i+1][j+1]) (g[sn][i+1][j+1] += g[sn][i][j]) %= mod; 
					}
				} 
			}
			
			for (int st = 0;st <= n;st++) {
				if (mk[0][st]) continue; 
				f[sn][st][0][st] = 1; 
				for (int i = 0;i < k;i++) {
					for (int j = 0;j <= n;j++) {
						if (!mk[i+1][j]) (f[sn][st][i+1][j] += f[sn][st][i][j]) %= mod; 
						if (!mk[i+1][j+1]) (f[sn][st][i+1][j+1] += f[sn][st][i][j]) %= mod; 
					}
				}
			}
		}
	}
	void chk () {
		int sd = sv[sz]; 
		for (int i = 1;i < sz;i++) {
			for (int j = 1;j < sz;j++) {
				dt[i][j-1] = f[sd][sv[i]+(sz-i-1)*(k/2)][k][sv[j]+(sz-j)*(k/2)];
			}
		}
		for (int i = 1;i < sz;i++) dt[0][i-1] = g[sd][k][sv[i]+(sz-i)*(k/2)]; //, cout << "CHECK:" << sz << " " << sv[i] << " " << sv[i]+(sz-i)*(k/2) << endl; 
		for (int i = 0;i < sz;i++) dt[i][sz-1] = f[sd][sv[i]+(sz-i-1)*(k/2)][n%k][sv[sz]]; 
//		cout << "SZ:"; for (int i = 1;i <= sz;i++) cout << sv[i] << " "; cout << endl; 
//		for (int i = 0;i < sz;i++) {
//			for (int j = 0;j < sz;j++) {
//				cout << dt[i][j] << " "; 
//			} cout << endl ;
//		} cout << endl; 
		memset(sf, 0, sizeof sf); 
		sf[0] = 1; 
		for (int i = 1;i < (1<<sz);i++) {
			for (int j = 0;j < sz;j++) {
				if ((i>>j&1)^1) continue; 
				int o = __builtin_popcount((i-(1<<j))&((1<<sz)-(1<<j)))&1 ? -1 : 1;  
				(sf[i] += 1ll*sf[i-(1<<j)]*o*dt[__builtin_popcount(i)-1][j]%mod) %= mod; 
			}
		}
//		cout << sf[(1<<sz)-1] << endl; 	
		(ans += sf[(1<<sz)-1]) %= mod; 
	}
	void dfs (int p, int s) {
		if (p > sz) return chk(); 
		for (int i = s;i < s+k/2;i++) {
			sv[p] = i; dfs(p+1, i); 
		}
	}
	void sol () {
		dfs(1, 0); 
	}
	void solve () {
		sz = n/k+1; 
		init(); sol(); 
		for (int i = 0;i < m;i++) str[i] ^= 1; 
		init(); sol(); 
		cout << ans; 
	}
}

void solve () {
	cin >> n >> k >> m; 
	if (m) cin >> str; 
	if (k <= 22) {
		T1::solve(); return; 
	}
	T2::solve(); 
}

signed main () {
	int T = 1; 
	while (T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 7664kb

input:

2 2 0

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 10
Accepted
time: 1ms
memory: 7904kb

input:

2 2 1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 10
Accepted
time: 0ms
memory: 38508kb

input:

3 2 0

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 10
Accepted
time: 3ms
memory: 38436kb

input:

3 2 1
0

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 10
Accepted
time: 3ms
memory: 38672kb

input:

4 2 0

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 10
Accepted
time: 0ms
memory: 38504kb

input:

4 2 1
0

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 10
Accepted
time: 0ms
memory: 7880kb

input:

4 4 0

output:

10

result:

ok 1 number(s): "10"

Test #8:

score: 10
Accepted
time: 0ms
memory: 7788kb

input:

4 4 1
1

output:

5

result:

ok 1 number(s): "5"

Test #9:

score: 10
Accepted
time: 1ms
memory: 7944kb

input:

4 4 2
00

output:

3

result:

ok 1 number(s): "3"

Test #10:

score: 10
Accepted
time: 1ms
memory: 7748kb

input:

4 4 3
101

output:

1

result:

ok 1 number(s): "1"

Test #11:

score: 10
Accepted
time: 4ms
memory: 38512kb

input:

5 2 0

output:

2

result:

ok 1 number(s): "2"

Test #12:

score: 10
Accepted
time: 7ms
memory: 38496kb

input:

5 2 1
1

output:

1

result:

ok 1 number(s): "1"

Test #13:

score: 10
Accepted
time: 0ms
memory: 38488kb

input:

5 4 0

output:

14

result:

ok 1 number(s): "14"

Test #14:

score: 10
Accepted
time: 0ms
memory: 38500kb

input:

5 4 1
0

output:

7

result:

ok 1 number(s): "7"

Test #15:

score: 10
Accepted
time: 8ms
memory: 38436kb

input:

5 4 2
01

output:

3

result:

ok 1 number(s): "3"

Test #16:

score: 10
Accepted
time: 0ms
memory: 38404kb

input:

5 4 3
110

output:

1

result:

ok 1 number(s): "1"

Test #17:

score: 10
Accepted
time: 29ms
memory: 38376kb

input:

17 2 0

output:

2

result:

ok 1 number(s): "2"

Test #18:

score: 10
Accepted
time: 29ms
memory: 38356kb

input:

17 2 0

output:

2

result:

ok 1 number(s): "2"

Test #19:

score: 10
Accepted
time: 19ms
memory: 38668kb

input:

17 10 6
110111

output:

621

result:

ok 1 number(s): "621"

Test #20:

score: 10
Accepted
time: 21ms
memory: 38364kb

input:

17 10 2
11

output:

8413

result:

ok 1 number(s): "8413"

Test #21:

score: 10
Accepted
time: 34ms
memory: 38380kb

input:

18 2 1
1

output:

1

result:

ok 1 number(s): "1"

Test #22:

score: 10
Accepted
time: 31ms
memory: 38504kb

input:

18 2 1
1

output:

1

result:

ok 1 number(s): "1"

Test #23:

score: 10
Accepted
time: 23ms
memory: 38444kb

input:

18 8 5
00010

output:

918

result:

ok 1 number(s): "918"

Test #24:

score: 10
Accepted
time: 24ms
memory: 38432kb

input:

18 8 3
001

output:

3404

result:

ok 1 number(s): "3404"

Test #25:

score: 10
Accepted
time: 3ms
memory: 38380kb

input:

18 16 6
100011

output:

2458

result:

ok 1 number(s): "2458"

Test #26:

score: 10
Accepted
time: 3ms
memory: 38428kb

input:

18 16 8
00101101

output:

548

result:

ok 1 number(s): "548"

Test #27:

score: 10
Accepted
time: 41ms
memory: 38632kb

input:

19 2 1
1

output:

1

result:

ok 1 number(s): "1"

Test #28:

score: 10
Accepted
time: 36ms
memory: 38492kb

input:

19 2 0

output:

2

result:

ok 1 number(s): "2"

Test #29:

score: 10
Accepted
time: 24ms
memory: 38488kb

input:

19 6 2
00

output:

3413

result:

ok 1 number(s): "3413"

Test #30:

score: 10
Accepted
time: 24ms
memory: 38628kb

input:

19 6 1
1

output:

7012

result:

ok 1 number(s): "7012"

Test #31:

score: 10
Accepted
time: 14ms
memory: 38400kb

input:

19 12 10
1010110000

output:

266

result:

ok 1 number(s): "266"

Test #32:

score: 10
Accepted
time: 16ms
memory: 38428kb

input:

19 12 3
111

output:

19234

result:

ok 1 number(s): "19234"

Test #33:

score: 10
Accepted
time: 4ms
memory: 38660kb

input:

19 16 2
10

output:

77876

result:

ok 1 number(s): "77876"

Test #34:

score: 10
Accepted
time: 8ms
memory: 38508kb

input:

19 16 0

output:

301208

result:

ok 1 number(s): "301208"

Test #35:

score: 10
Accepted
time: 38ms
memory: 38504kb

input:

20 2 1
0

output:

1

result:

ok 1 number(s): "1"

Test #36:

score: 10
Accepted
time: 36ms
memory: 38380kb

input:

20 2 0

output:

2

result:

ok 1 number(s): "2"

Test #37:

score: 10
Accepted
time: 22ms
memory: 38360kb

input:

20 10 9
110111000

output:

76

result:

ok 1 number(s): "76"

Test #38:

score: 10
Accepted
time: 25ms
memory: 38464kb

input:

20 10 9
110101110

output:

372

result:

ok 1 number(s): "372"

Test #39:

score: 10
Accepted
time: 16ms
memory: 38488kb

input:

20 14 11
10110110000

output:

207

result:

ok 1 number(s): "207"

Test #40:

score: 10
Accepted
time: 11ms
memory: 38508kb

input:

20 14 7
0011011

output:

3675

result:

ok 1 number(s): "3675"

Test #41:

score: 10
Accepted
time: 7ms
memory: 11708kb

input:

20 20 14
10111010000000

output:

58

result:

ok 1 number(s): "58"

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #42:

score: 10
Accepted
time: 213ms
memory: 38672kb

input:

114 12 11
11010000010

output:

394940507

result:

ok 1 number(s): "394940507"

Test #43:

score: 10
Accepted
time: 211ms
memory: 38428kb

input:

114 12 2
01

output:

60509873

result:

ok 1 number(s): "60509873"

Test #44:

score: 10
Accepted
time: 209ms
memory: 38424kb

input:

114 14 10
1001111011

output:

154687039

result:

ok 1 number(s): "154687039"

Test #45:

score: 10
Accepted
time: 212ms
memory: 38504kb

input:

114 14 5
00100

output:

941826071

result:

ok 1 number(s): "941826071"

Test #46:

score: 10
Accepted
time: 215ms
memory: 38380kb

input:

114 16 10
1011101001

output:

391666362

result:

ok 1 number(s): "391666362"

Test #47:

score: 10
Accepted
time: 215ms
memory: 40468kb

input:

114 16 15
000010011111010

output:

599226561

result:

ok 1 number(s): "599226561"

Test #48:

score: 10
Accepted
time: 250ms
memory: 40552kb

input:

114 18 1
0

output:

167675624

result:

ok 1 number(s): "167675624"

Test #49:

score: 10
Accepted
time: 247ms
memory: 40672kb

input:

114 18 8
11000001

output:

165986235

result:

ok 1 number(s): "165986235"

Test #50:

score: 10
Accepted
time: 418ms
memory: 42456kb

input:

114 20 17
11101000010011010

output:

852476378

result:

ok 1 number(s): "852476378"

Test #51:

score: 10
Accepted
time: 414ms
memory: 42476kb

input:

114 20 13
1101011010000

output:

974712368

result:

ok 1 number(s): "974712368"

Test #52:

score: 10
Accepted
time: 213ms
memory: 38436kb

input:

113 12 8
10101100

output:

754580060

result:

ok 1 number(s): "754580060"

Test #53:

score: 10
Accepted
time: 223ms
memory: 38492kb

input:

113 12 10
1110010010

output:

928476173

result:

ok 1 number(s): "928476173"

Test #54:

score: 10
Accepted
time: 211ms
memory: 38380kb

input:

113 14 9
010111000

output:

930953494

result:

ok 1 number(s): "930953494"

Test #55:

score: 10
Accepted
time: 205ms
memory: 38380kb

input:

113 14 0

output:

613264431

result:

ok 1 number(s): "613264431"

Test #56:

score: 10
Accepted
time: 222ms
memory: 38624kb

input:

113 16 4
0011

output:

966491874

result:

ok 1 number(s): "966491874"

Test #57:

score: 10
Accepted
time: 216ms
memory: 38424kb

input:

113 16 10
1110110011

output:

71975445

result:

ok 1 number(s): "71975445"

Test #58:

score: 10
Accepted
time: 247ms
memory: 40496kb

input:

113 18 2
01

output:

35416931

result:

ok 1 number(s): "35416931"

Test #59:

score: 10
Accepted
time: 252ms
memory: 38636kb

input:

113 18 11
01101011111

output:

605684813

result:

ok 1 number(s): "605684813"

Test #60:

score: 10
Accepted
time: 414ms
memory: 42460kb

input:

113 20 1
1

output:

970488755

result:

ok 1 number(s): "970488755"

Test #61:

score: 10
Accepted
time: 409ms
memory: 42724kb

input:

113 20 17
10000001101111001

output:

308768022

result:

ok 1 number(s): "308768022"

Test #62:

score: 10
Accepted
time: 209ms
memory: 38428kb

input:

112 12 10
1011100000

output:

379472486

result:

ok 1 number(s): "379472486"

Test #63:

score: 10
Accepted
time: 203ms
memory: 38472kb

input:

112 12 3
111

output:

876338776

result:

ok 1 number(s): "876338776"

Test #64:

score: 10
Accepted
time: 212ms
memory: 38596kb

input:

112 14 6
100111

output:

850899867

result:

ok 1 number(s): "850899867"

Test #65:

score: 10
Accepted
time: 221ms
memory: 38596kb

input:

112 14 11
11011001011

output:

579315503

result:

ok 1 number(s): "579315503"

Test #66:

score: 10
Accepted
time: 232ms
memory: 40432kb

input:

112 16 11
00000111111

output:

827780781

result:

ok 1 number(s): "827780781"

Test #67:

score: 10
Accepted
time: 221ms
memory: 38400kb

input:

112 16 9
101001101

output:

247916257

result:

ok 1 number(s): "247916257"

Test #68:

score: 10
Accepted
time: 262ms
memory: 40540kb

input:

112 18 16
0011000001111001

output:

740632908

result:

ok 1 number(s): "740632908"

Test #69:

score: 10
Accepted
time: 272ms
memory: 40432kb

input:

112 18 4
0010

output:

594108528

result:

ok 1 number(s): "594108528"

Test #70:

score: 10
Accepted
time: 414ms
memory: 42692kb

input:

112 20 7
1010100

output:

818166882

result:

ok 1 number(s): "818166882"

Test #71:

score: 10
Accepted
time: 425ms
memory: 42768kb

input:

112 20 16
0001100100101000

output:

222914924

result:

ok 1 number(s): "222914924"

Test #72:

score: 10
Accepted
time: 204ms
memory: 38672kb

input:

111 12 2
11

output:

895626591

result:

ok 1 number(s): "895626591"

Test #73:

score: 10
Accepted
time: 202ms
memory: 38320kb

input:

111 12 1
1

output:

543447881

result:

ok 1 number(s): "543447881"

Test #74:

score: 10
Accepted
time: 209ms
memory: 38368kb

input:

111 14 3
111

output:

555958815

result:

ok 1 number(s): "555958815"

Test #75:

score: 10
Accepted
time: 216ms
memory: 38380kb

input:

111 14 13
1110001101010

output:

47749667

result:

ok 1 number(s): "47749667"

Test #76:

score: 10
Accepted
time: 214ms
memory: 38600kb

input:

111 16 5
01000

output:

880732287

result:

ok 1 number(s): "880732287"

Test #77:

score: 10
Accepted
time: 208ms
memory: 38496kb

input:

111 16 7
0110010

output:

153134396

result:

ok 1 number(s): "153134396"

Test #78:

score: 10
Accepted
time: 271ms
memory: 40552kb

input:

111 18 17
11011101001111100

output:

718197735

result:

ok 1 number(s): "718197735"

Test #79:

score: 10
Accepted
time: 242ms
memory: 40708kb

input:

111 18 9
011110101

output:

78875109

result:

ok 1 number(s): "78875109"

Test #80:

score: 10
Accepted
time: 411ms
memory: 42688kb

input:

111 20 6
100101

output:

484008568

result:

ok 1 number(s): "484008568"

Test #81:

score: 10
Accepted
time: 399ms
memory: 42476kb

input:

111 20 19
1100110110001010110

output:

612558978

result:

ok 1 number(s): "612558978"

Test #82:

score: 10
Accepted
time: 354ms
memory: 42772kb

input:

102 20 10
0101000100

output:

678899105

result:

ok 1 number(s): "678899105"

Test #83:

score: 10
Accepted
time: 167ms
memory: 38592kb

input:

97 16 13
0101110011010

output:

456291266

result:

ok 1 number(s): "456291266"

Subtask #3:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #84:

score: 30
Accepted
time: 218ms
memory: 42756kb

input:

66 20 5
11001

output:

286180948

result:

ok 1 number(s): "286180948"

Test #85:

score: 30
Accepted
time: 212ms
memory: 42456kb

input:

66 20 19
0101001111011100100

output:

334317215

result:

ok 1 number(s): "334317215"

Test #86:

score: 30
Accepted
time: 515ms
memory: 54228kb

input:

66 22 19
1001101100000100001

output:

465510840

result:

ok 1 number(s): "465510840"

Test #87:

score: 30
Accepted
time: 525ms
memory: 53788kb

input:

66 22 11
10001111000

output:

731812403

result:

ok 1 number(s): "731812403"

Test #88:

score: 0
Wrong Answer
time: 59ms
memory: 394100kb

input:

66 24 6
011111

output:

559836359

result:

wrong answer 1st numbers differ - expected: '270615978', found: '559836359'

Subtask #4:

score: 0
Wrong Answer

Test #137:

score: 20
Accepted
time: 422ms
memory: 42532kb

input:

114 20 0

output:

849724285

result:

ok 1 number(s): "849724285"

Test #138:

score: 20
Accepted
time: 1039ms
memory: 52980kb

input:

114 22 0

output:

918046462

result:

ok 1 number(s): "918046462"

Test #139:

score: 0
Wrong Answer
time: 351ms
memory: 394576kb

input:

114 24 0

output:

-527074787

result:

wrong answer 1st numbers differ - expected: '471169566', found: '-527074787'

Subtask #5:

score: 0
Skipped

Dependency #2:

100%
Accepted

Dependency #3:

0%