QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#769601 | #5162. 种花 | Link_Cut_Y | 100 ✓ | 124ms | 20884kb | C++14 | 3.6kb | 2024-11-21 18:28:12 | 2024-11-21 18:28:13 |
Judging History
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, 0, n + 1) rep(j, 0, m + 1) 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;
}
这程序好像有点Bug,我给组数据试试?
详细
Pretests
Final Tests
Test #1:
score: 1
Accepted
time: 20ms
memory: 20704kb
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: 7936kb
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: 0ms
memory: 7952kb
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: 20884kb
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: 111ms
memory: 20816kb
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: 6
Accepted
time: 116ms
memory: 20824kb
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: 10
Accepted
time: 1ms
memory: 7880kb
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: 6
Accepted
time: 1ms
memory: 5992kb
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 151 121 52 47
result:
ok 5 lines
Test #9:
score: 6
Accepted
time: 1ms
memory: 8044kb
input:
5 9 28 29 1 1 01000000000001000000000000100 00001000010000000000010000001 00000000000000000000000000001 00000100000000100001100100100 00001110100010100011000000000 00000000000000010000100010010 00001000000000000000000000000 00000000000000000010000000000 01000000000010000001001000010 0000100000001010...
output:
117502 565585 11489 25154 4162 8339 473 352 132 115
result:
ok 5 lines
Test #10:
score: 8
Accepted
time: 0ms
memory: 8144kb
input:
5 10 48 50 1 1 01001000001000001000000000001000010000000000000000 00000000000000100000100101000000000000000001000000 00001000000100000100000000110000000000000000000000 00000000000000000000000000000001000100000000001001 00100000000000000000000100010000000010000000000100 001000000000000100000000101000...
output:
847186 6581666 81195 259022 6965 10793 2308 3158 529 516
result:
ok 5 lines
Test #11:
score: 10
Accepted
time: 2ms
memory: 8156kb
input:
5 11 95 90 1 1 001100000100000011000000000000000100000000000001000000000000000100000010000000000000000000 000000000000000000000000000000100000000000000000000100000000000000000000100000000010000000 000000000100000000011000000010001000000000000000000001100000010000000000100001000010000000 000000000000...
output:
3308449 27745538 327127 1213705 44875 88885 10033 14745 1823 1423
result:
ok 5 lines
Test #12:
score: 6
Accepted
time: 6ms
memory: 10476kb
input:
5 12 187 184 1 1 0000000010101000000010000000000000100001000000000000000001000000010000000000000100100000000100000000010000000000000000100000000000010000010000000000000010000001000000100000000101000000 00000000000000000000000000000000000000010000000100000100000000000000000000000000000001010000000010...
output:
18087075 150234004 1259249 4715215 236348 571474 43837 64502 8531 8367
result:
ok 5 lines
Test #13:
score: 6
Accepted
time: 12ms
memory: 12404kb
input:
5 13 271 300 1 1 0000000100000010000000100000000110000000000100000001001000100100000000000000100001000100000001001000000000000000000000001000000000000000010100000000000000000000000100000000010000000000000000000000000001001000000000010000000000010000000001000000000000000000000010000000000010000000000...
output:
42365220 358193357 3095089 11638923 485642 1141183 95052 141468 20883 21431
result:
ok 5 lines
Test #14:
score: 8
Accepted
time: 31ms
memory: 14512kb
input:
5 14 500 476 1 1 0000000000000000001110000000010001000000000000000010000000000100000000000000100000000000001000000001000000000000100000001000001001101000000001000000000101000000000010000001100100000100000010100000000000000100100000000000000000001011000000000000011000000000000000000000000000010100001...
output:
132646140 185264487 9978992 39570487 1460852 3463881 290847 445053 50919 50710
result:
ok 5 lines
Test #15:
score: 6
Accepted
time: 115ms
memory: 20812kb
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: 14
Accepted
time: 124ms
memory: 20652kb
input:
5 16 1000 998 1 1 010001000000000101000000100101000000000000000000100000000000000000000100000110010010000000100000000100000000000000000001000000000001000000010000000010000100000011000000000000000000010000000000000100000100000001000000010000000000000000000000000000000000000000000000000111001000000000...
output:
575874014 131845186 39748874 155407788 6206382 14467888 1175981 1745889 244602 238670
result:
ok 5 lines
Extra Test:
score: 0
Extra Test Passed