QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#251603#5162. 种花IANYEYZ15 279ms51316kbC++142.4kb2023-11-14 21:43:052023-11-14 21:43:05

Judging History

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

  • [2023-11-14 21:43:05]
  • 评测
  • 测评结果:15
  • 用时:279ms
  • 内存:51316kb
  • [2023-11-14 21:43:05]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#define int unsigned long long
using namespace std;
int a[1010][1010],sum[1010][1010],ssum[1010][1010],vs[1010][1010],vsum[1010][1010],vsu[1010][1010],t,id,n,m,c,f,ans,ans1;
/* utility */


/* checker */


/* Solution */
void Solve1() {
	cout << 0 << " " << 0 << "\n";
}
void Solve100() {
	for(int i = 1;i <= m;i++) {
		vs[n + 1][i] = n + 1;
		vsu[0][i] = 0;
	}
	for(int i = n;i >= 1;i--) {
		for(int j = 1;j <= m;j++) {
			ssum[i][j] = ssum[i + 1][j] + sum[i][j];
			if(!a[i][j]) vs[i][j] = vs[i + 1][j];
			else vs[i][j] = i;
		}
	}
	for(int i = 1;i <= n;i++) {
		for(int j = 1;j <= m;j++) {
			vsum[i][j] = vsum[i - 1][j] + sum[i][j];
			if(!a[i][j]) vsu[i][j] = vsu[i - 1][j];
			else vsu[i][j] = i;
		}
	}
	/*for(int i = 1;i <= n;i++) {
		for(int j = 1;j <= m;j++) {
			cout << sum[i][j] << " ";
		}
		cout << "\n";
	}*/ 
	for(int i = 1;i <= m;i++) {
		for(int j = 1;j <= n - 2;j++) {
			if(a[j][i]) continue;
			int mmax = vs[j][i] - 1;
			if(mmax <= j + 1) continue;
			(ans += sum[j][i + 1] * (ssum[j + 2][i + 1] - ssum[mmax + 1][i + 1]) % 998244353) %= 998244353;
			//cout << j << " " << i << " " << sum[j][i + 1] << " " << (ssum[j + 2][i + 1] - ssum[mmax + 1][i + 1]) << " ";
		}
		//cout << "\n";
	}
	for(int i = 1;i <= m - 1;i++) {
		for(int j = n;j >= 3;j--) {
			int dn = vs[j][i] - j - 1;
			if(dn <= 0) continue;
			int mmax = vsu[j][i];
			if(mmax >= j - 2) continue;
			(ans1 += dn * (sum[j][i + 1]) % 998244353 * (vsum[j - 1][i + 1] - vsum[mmax][i + 1]) % 998244353) %= 998244353;
			//cout << j << " " << i << " " << dn << " " << sum[j][i + 1] << " " << (vsum[j - 1][i + 1] - vsum[mmax][i + 1]) << " ";
		}
		//cout << "\n";
	}
	cout << (ans * c) % 998244353 << " " << (ans1 * f) % 998244353 << "\n";
}

signed main()
{
	cin >> t >> id;
	while(t--) {
		cin >> n >> m >> c >> f;
		memset(a,0,sizeof(a));
		for(int i = 1;i <= n;i++) {
			for(int j = 1;j <= m;j++) {
				char c;
				cin >> c;
				if(c == '1') a[i][j] = 1;
				else a[i][j] = 0;
			}
		}
		memset(sum,0,sizeof(sum));
		memset(ssum,0,sizeof(ssum));
		memset(vsum,0,sizeof(vsum));
		memset(vs,0,sizeof(vs));
		memset(vsu,0,sizeof(vsu));
		ans = 0,ans1 = 0;
		for(int i = 1;i <= n;i++) {
			for(int j = m;j >= 1;j--) {
				if(!a[i][j]) sum[i][j] = sum[i][j + 1] + 1;
				else sum[i][j] = 0;
			}
		}
		if(c == 0 && f == 0) {
			Solve1();
		} else {
			Solve100();
		}
	}
}

詳細信息

Test #1:

score: 1
Accepted
time: 36ms
memory: 51236kb

input:

1 1
998 1000 0 0
0000100000100001000000000000011100000000010100100010000001100000000100011010000000011010001000100010000010001000011110010000000000010100000000001000000010000000100001000000101000010010010000000010010010000010001000010000000010000100001001001111010000000000010000000000100001111010011...

output:

0 0

result:

ok single line: '0 0'

Test #2:

score: 2
Accepted
time: 3ms
memory: 51196kb

input:

3 2
3 2 1 1
00
00
00
3 2 1 1
00
01
00
3 2 1 1
00
00
01

output:

1 0
1 0
0 0

result:

ok 3 lines

Test #3:

score: 0
Wrong Answer
time: 9ms
memory: 51312kb

input:

5 3
4 2 1 1
00
00
00
00
4 2 1 1
00
01
00
00
4 2 1 1
00
00
01
00
4 2 1 1
00
00
00
01
4 2 1 1
00
00
00
10

output:

3 2
2 1
2 0
1 2
1 0

result:

wrong answer 1st lines differ - expected: '3 1', found: '3 2'

Test #4:

score: 0
Wrong Answer
time: 13ms
memory: 51192kb

input:

5 4
997 2 1 1
10
00
00
00
00
00
00
00
00
00
00
10
00
00
10
00
00
00
00
00
00
00
00
00
00
01
00
00
00
00
00
00
00
00
10
00
00
00
01
11
00
00
00
00
00
00
00
00
10
00
00
00
00
00
10
01
00
00
00
00
00
00
00
01
01
00
00
00
10
00
00
00
00
00
00
00
00
00
10
00
00
00
00
00
00
00
00
00
10
00
00
00
00
00
00
0...

output:

5301 43206
1309 5387
841 2997
181 330
56 106

result:

wrong answer 1st lines differ - expected: '5301 38550', found: '5301 43206'

Test #5:

score: 0
Wrong Answer
time: 245ms
memory: 51240kb

input:

5 5
999 998 1 1
00100100100100101100100100100100100100100100110100110100101100100100110100100100100101100100110100100100101100101100101100100100100100100100101100101100110100100100110100100100100100100110100101110100101110100100110100100100100101100100100100100100101100100100100100100100100100100100...

output:

1952124 19247215
546673 2610570
186900 562306
63889 133255
20937 30507

result:

wrong answer 1st lines differ - expected: '1952124 17488577', found: '1952124 19247215'

Test #6:

score: 6
Accepted
time: 229ms
memory: 51152kb

input:

5 6
995 1000 1 1
0000000000100101000000000000000000001010000100000000000000000100100000000001000000000000000000100000000101000000000000000000000000000000000000000000000001000000000000000100100000001000000000010000000000000000000000000100000000100000001011000100000000110000000000000000000000000000000...

output:

14235129 0
1993965 0
454532 0
118724 0
31475 0

result:

ok 5 lines

Test #7:

score: 0
Wrong Answer
time: 17ms
memory: 51316kb

input:

5 7
10 10 1 1
0000000000
0000000100
0000100000
0000000000
0000000000
0000000000
0000000001
0000000000
0010000001
0000000000
9 10 1 1
1000000000
0000100000
0000010100
0001000001
0000000000
1001000001
0111010011
0000000100
0100001000
9 10 1 1
1100000001
0101100010
0010010000
0111010110
1001000110
1110...

output:

5890 16816
437 763
9 18
39 26
5 0

result:

wrong answer 1st lines differ - expected: '5890 12768', found: '5890 16816'

Test #8:

score: 0
Wrong Answer
time: 12ms
memory: 51236kb

input:

5 8
20 18 1 1
010010000010000000
000000000010000110
000000101000000000
000000000000001000
000000000000000000
000000010000000000
010000000010100000
000100000100000001
000000000000001010
000000000100000000
000000100000000001
000001000000100000
000000000100001010
100000000000000000
000000000000000100
0...

output:

32999 156562
11013 43831
357 479
151 187
52 91

result:

wrong answer 1st lines differ - expected: '32999 126558', found: '32999 156562'

Test #9:

score: 0
Wrong Answer
time: 8ms
memory: 51176kb

input:

5 9
28 29 1 1
01000000000001000000000000100
00001000010000000000010000001
00000000000000000000000000001
00000100000000100001100100100
00001110100010100011000000000
00000000000000010000100010010
00001000000000000000000000000
00000000000000000010000000000
01000000000010000001001000010
0000100000001010...

output:

117502 647935
11489 33814
4162 11431
473 866
132 167

result:

wrong answer 1st lines differ - expected: '117502 565585', found: '117502 647935'

Test #10:

score: 0
Wrong Answer
time: 13ms
memory: 51072kb

input:

5 10
48 50 1 1
01001000001000001000000000001000010000000000000000
00000000000000100000100101000000000000000001000000
00001000000100000100000000110000000000000000000000
00000000000000000000000000000001000100000000001001
00100000000000000000000100010000000010000000000100
001000000000000100000000101000...

output:

847186 7468495
81195 328194
6965 14814
2308 4373
529 737

result:

wrong answer 1st lines differ - expected: '847186 6581666', found: '847186 7468495'

Test #11:

score: 0
Wrong Answer
time: 15ms
memory: 51196kb

input:

5 11
95 90 1 1
001100000100000011000000000000000100000000000001000000000000000100000010000000000000000000
000000000000000000000000000000100000000000000000000100000000000000000000100000000010000000
000000000100000000011000000010001000000000000000000001100000010000000000100001000010000000
000000000000...

output:

3308449 30749482
327127 1466254
44875 118336
10033 20622
1823 2317

result:

wrong answer 1st lines differ - expected: '3308449 27745538', found: '3308449 30749482'

Test #12:

score: 0
Wrong Answer
time: 18ms
memory: 51148kb

input:

5 12
187 184 1 1
0000000010101000000010000000000000100001000000000000000001000000010000000000000100100000000100000000010000000000000000100000000000010000010000000000000010000001000000100000000101000000
00000000000000000000000000000000000000010000000100000100000000000000000000000000000001010000000010...

output:

18087075 167034586
1259249 5689718
236348 732974
43837 89556
8531 12964

result:

wrong answer 1st lines differ - expected: '18087075 150234004', found: '18087075 167034586'

Test #13:

score: 0
Wrong Answer
time: 35ms
memory: 51172kb

input:

5 13
271 300 1 1
0000000100000010000000100000000110000000000100000001001000100100000000000000100001000100000001001000000000000000000000001000000000000000010100000000000000000000000100000000010000000000000000000000000001001000000000010000000000010000000001000000000000000000000010000000000010000000000...

output:

42365220 395784630
3095089 14054196
485642 1489662
95052 197675
20883 31501

result:

wrong answer 1st lines differ - expected: '42365220 358193357', found: '42365220 395784630'

Test #14:

score: 0
Wrong Answer
time: 65ms
memory: 51192kb

input:

5 14
500 476 1 1
0000000000000000001110000000010001000000000000000010000000000100000000000000100000000000001000000001000000000000100000001000001001101000000001000000000101000000000010000001100100000100000010100000000000000100100000000000000000001011000000000000011000000000000000000000000000010100001...

output:

132646140 305121097
9978992 47453333
1460852 4498784
290847 617034
50919 76206

result:

wrong answer 1st lines differ - expected: '132646140 185264487', found: '132646140 305121097'

Test #15:

score: 6
Accepted
time: 265ms
memory: 51200kb

input:

5 15
995 999 1 0
0100000000000000000010000000000000000001000000000000000000000110000100000000000000000000000100000000000000000000001000000000000100000000100000000010000000010010000000000010000100100110000010000000000000000100000100000000000000001000010100000000000000000000000000010000000001000000000...

output:

569370923 0
40349163 0
6144080 0
1186094 0
249688 0

result:

ok 5 lines

Test #16:

score: 0
Wrong Answer
time: 279ms
memory: 51308kb

input:

5 16
1000 998 1 1
010001000000000101000000100101000000000000000000100000000000000000000100000110010010000000100000000100000000000000000001000000000001000000010000000010000100000011000000000000000000010000000000000100000100000001000000010000000000000000000000000000000000000000000000000111001000000000...

output:

575874014 648555515
39748874 186896346
6206382 18835557
1175981 2449569
244602 360628

result:

wrong answer 1st lines differ - expected: '575874014 131845186', found: '575874014 648555515'