QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767089#5162. 种花Link_Cut_Y#24 124ms20712kbC++143.6kb2024-11-20 19:48:372024-11-20 19:48:39

Judging History

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

  • [2024-11-20 19:48:39]
  • 评测
  • 测评结果:24
  • 用时:124ms
  • 内存:20712kb
  • [2024-11-20 19:48:37]
  • 提交

answer

#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); i ++ )
#define rop(i, a, b) for (int i = (a); i < (b); i ++ )
#define dep(i, a, b) for (int i = (a); i >= (b); i -- )
#define dop(i, a, b) for (int i = (a); i > (b); i -- )

#define Darr(a, L, R) cerr << #a "[" << L << " ~ " << R << "] = "; rep(x, L, R) cerr << a[x] << " "; cerr << '\n';
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define D(x) (cerr << #x << " = " << x << '\n')
#define vit vector<int>::iterator
#define all(x) x.begin(), x.end()
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define chkmin(a, b) (a = min(a, b))
#define chkmax(a, b) (a = max(a, b))
#define sit set<int>::iterator
#define lowbit(x) (x & -x)
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pi acos(-1)
#define gc getchar
#define pc putchar
#define db double
#define y second
#define x first

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<db, db> PDD;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int mod = 998244353;
const int eps = 1e-9;

const int N = 1010; int T = 1, id = 1;
void print(int x) { dep(i, 20, 0) pc(((x >> i) & 1) ? '1' : '0'); }
int qpow(int a, int b = mod - 2, int s = 1) { for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) s = 1ll * s * a % mod; return s; }
namespace IO {
	void read() { return; }
	void write(char ch) { pc(ch); return; }
	void write() { return; }
	template <typename T> void read(T &x) { x = 0; T w = 0; char ch = gc(); while (ch < '0' || ch > '9') w |= (ch == '-'), ch = gc(); while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ 48), ch = gc(); x = w ? -x : x; }
	template <typename T> void print(T x) { if (!x) return; print<T>(x / 10), pc((x % 10) ^ '0'); }
	template <typename T> void write(T x) { if (x > 0) print<T>(x); else if (x < 0) pc('-'), print<T>(-x); else pc('0'); }
	template <typename T> void write(T x, char en) { write<T>(x), pc(en); }
	template <typename T, typename ...T2> void read(T &s, T2 &...oth) { read(s); read(oth...); return; }
}; using namespace IO;

int n, m, c, f;
int suf[N][N], s[N][N];
char g[N][N];
void sub() {
	read(n, m, c, f);
	rep(i, 1, n) rep(j, 1, m) suf[i][j] = s[i][j] = 0;
	rep(i, 1, n) scanf("%s", g[i] + 1);
	rep(i, 1, n) dep(j, m, 1) if (g[i][j] == '0') 
		suf[i][j] = suf[i][j + 1] + 1; // 从 (i, j) 向后延伸的最大长度 
	rep(j, 1, m) rep(i, 1, n) if (g[i][j] == '0')
		s[i][j] = s[i - 1][j] + suf[i][j] - 1;
	rep(i, 2, n) rep(j, 1, m) {
		if (g[i][j] == '0') s[i][j] -= suf[i][j] - 1;
		if (g[i - 1][j] == '0') s[i][j] -= suf[i - 1][j] - 1;
	}
	rep(i, 1, n) rep(j, 1, m) s[i][j] %= mod;
	auto calc_C = [&]() -> int {
		int ans = 0;
		rep(i, 3, n) rep(j, 1, m - 1) if (g[i][j] == '0')
			ans = (ans + s[i][j] * (suf[i][j] - 1) % mod) % mod;
		return (ans % mod + mod) % mod;
	};
	auto calc_F = [&]() -> int {
		int ans = 0;
		rep(j, 1, m - 1) {
			int cnt = 0;
			dep(i, n, 3) {
				if (g[i][j] == '0') cnt ++ ; else cnt = 0; if (!cnt) continue;
				ans = (ans + s[i][j] * (suf[i][j] - 1) % mod * (cnt - 1) % mod) % mod;
			}
		} return (ans % mod + mod) % mod;
	};
	printf("%lld %lld\n", c * calc_C() % mod, f * calc_F() % mod);
}
signed main() {
	read(T, id);
	while (T -- ) sub();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 1
Accepted
time: 18ms
memory: 20560kb

input:

1 1
998 1000 0 0
0000100000100001000000000000011100000000010100100010000001100000000100011010000000011010001000100010000010001000011110010000000000010100000000001000000010000000100001000000101000010010010000000010010010000010001000010000000010000100001001001111010000000000010000000000100001111010011...

output:

0 0

result:

ok single line: '0 0'

Test #2:

score: 2
Accepted
time: 1ms
memory: 5828kb

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: 3
Accepted
time: 1ms
memory: 7764kb

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 1
2 1
2 0
1 1
1 0

result:

ok 5 lines

Test #4:

score: 4
Accepted
time: 0ms
memory: 19868kb

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 38550
1309 4386
841 2387
181 228
56 78

result:

ok 5 lines

Test #5:

score: 4
Accepted
time: 94ms
memory: 20500kb

input:

5 5
999 998 1 1
00100100100100101100100100100100100100100100110100110100101100100100110100100100100101100100110100100100101100101100101100100100100100100100101100101100110100100100110100100100100100100110100101110100101110100100110100100100100101100100100100100100101100100100100100100100100100100100...

output:

1952124 17488577
546673 2174022
186900 431806
63889 95010
20937 20375

result:

ok 5 lines

Test #6:

score: 0
Wrong Answer
time: 111ms
memory: 20712kb

input:

5 6
995 1000 1 1
0000000000100101000000000000000000001010000100000000000000000100100000000001000000000000000000100000000101000000000000000000000000000000000000000000000001000000000000000100100000001000000000010000000000000000000000000100000000100000001011000100000000110000000000000000000000000000000...

output:

14235129 0
2001544 0
456443 0
118724 0
31578 0

result:

wrong answer 2nd lines differ - expected: '1993965 0', found: '2001544 0'

Test #7:

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

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 12768
437 540
9 12
39 20
5 0

result:

ok 5 lines

Test #8:

score: 0
Wrong Answer
time: 1ms
memory: 7824kb

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 126558
11013 37023
357 333
171 143
64 77

result:

wrong answer 4th lines differ - expected: '151 121', found: '171 143'

Test #9:

score: 0
Wrong Answer
time: 1ms
memory: 7848kb

input:

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

output:

117502 565585
12496 27336
4162 8339
491 352
132 115

result:

wrong answer 2nd lines differ - expected: '11489 25154', found: '12496 27336'

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 7800kb

input:

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

output:

847186 6581666
81195 259022
8722 15490
2385 3282
529 516

result:

wrong answer 3rd lines differ - expected: '6965 10793', found: '8722 15490'

Test #11:

score: 0
Wrong Answer
time: 2ms
memory: 6280kb

input:

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

output:

3308449 27745538
327127 1213705
46835 91898
10033 14745
1927 1627

result:

wrong answer 3rd lines differ - expected: '44875 88885', found: '46835 91898'

Test #12:

score: 0
Wrong Answer
time: 3ms
memory: 10544kb

input:

5 12
187 184 1 1
0000000010101000000010000000000000100001000000000000000001000000010000000000000100100000000100000000010000000000000000100000000000010000010000000000000010000001000000100000000101000000
00000000000000000000000000000000000000010000000100000100000000000000000000000000000001010000000010...

output:

18087075 150234004
1259249 4715215
241929 585778
44713 65530
8614 8442

result:

wrong answer 3rd lines differ - expected: '236348 571474', found: '241929 585778'

Test #13:

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

input:

5 13
271 300 1 1
0000000100000010000000100000000110000000000100000001001000100100000000000000100001000100000001001000000000000000000000001000000000000000010100000000000000000000000100000000010000000000000000000000000001001000000000010000000000010000000001000000000000000000000010000000000010000000000...

output:

42365220 358193357
3274601 12243416
524089 1237175
97883 146105
20982 21516

result:

wrong answer 2nd lines differ - expected: '3095089 11638923', found: '3274601 12243416'

Test #14:

score: 0
Wrong Answer
time: 31ms
memory: 16568kb

input:

5 14
500 476 1 1
0000000000000000001110000000010001000000000000000010000000000100000000000000100000000000001000000001000000000000100000001000001001101000000001000000000101000000000010000001100100000100000010100000000000000100100000000000000000001011000000000000011000000000000000000000000000010100001...

output:

132646140 185264487
9978992 39570487
1460852 3463881
292875 446926
51326 51081

result:

wrong answer 4th lines differ - expected: '290847 445053', found: '292875 446926'

Test #15:

score: 0
Wrong Answer
time: 122ms
memory: 20664kb

input:

5 15
995 999 1 0
0100000000000000000010000000000000000001000000000000000000000110000100000000000000000000000100000000000000000000001000000000000100000000100000000010000000010010000000000010000100100110000010000000000000000100000100000000000000001000010100000000000000000000000000010000000001000000000...

output:

569370923 0
40447844 0
6151198 0
1188557 0
249688 0

result:

wrong answer 2nd lines differ - expected: '40349163 0', found: '40447844 0'

Test #16:

score: 0
Wrong Answer
time: 124ms
memory: 20608kb

input:

5 16
1000 998 1 1
010001000000000101000000100101000000000000000000100000000000000000000100000110010010000000100000000100000000000000000001000000000001000000010000000010000100000011000000000000000000010000000000000100000100000001000000010000000000000000000000000000000000000000000000000111001000000000...

output:

575874014 131845186
39748874 155407788
6212883 14480889
1180532 1751772
244602 238670

result:

wrong answer 3rd lines differ - expected: '6206382 14467888', found: '6212883 14480889'