QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#371442 | #244. Turn Off The Light | JWRuixi | 0 | 145ms | 24192kb | C++17 | 2.1kb | 2024-03-30 12:22:12 | 2024-03-30 12:22:13 |
Judging History
answer
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
using vi = vector<int>;
constexpr int N = 1e6 + 9;
constexpr int mod = 1e9 + 7;
int n, a[N], f[N][2], g[N], as[N];
char s[N];
IL void cmin (int &x, const int &y) {
x > y && (x = y, 0);
}
void slv () {
cin >> n >> (s + 1);
if (count(s + 1, s + n + 1, '1') == 0) {
cout << "0\n";
return;
}
if (count(s + 1, s + n + 1, '1') == 1) {
int p = find(s + 1, s + n + 1, '1') - s;
int z = 0;
L (i, 1, p - 1) {
z = (z + (LL)i * (2 * (p - i) - 1)) % mod;
}
z = (z + 3) % mod;
L (i, p + 1, n) {
z = (z + (LL)i * (2 * (i - p) - 1)) % mod;
}
cout << z << '\n';
return;
}
L (i, 1, n) {
a[i] = s[i] ^ 48;
}
memset(as, 0x3f, (n + 1) << 2);
L (o, 0, 1) {
int L, R;
L (i, 1, n) {
if (a[i]) {
L = i;
break;
}
}
R (i, n, 1) {
if (a[i]) {
R = i;
break;
}
}
L (i, R + 1, n + 1) {
f[i][0] = f[i][1] = 0;
}
f[R][0] = a[R] ? 0 : 3;
f[R][1] = a[R] ? 1 : 2;
R (i, R - 1, 1) {
f[i][0] = f[i + 1][a[i] ^ 1];
f[i][1] = f[i + 1][a[i]] + 2;
}
L (i, 0, L) {
g[i] = 0;
}
int C = 0;
L (i, L + 1, n) {
C += a[i - 1];
g[i] = g[i - 1] + (C % 2 ? 0 : 2);
}
C = 0;
L (p, 1, n) {
C += a[p - 1];
int l = min(p, L);
int r = max(p, R);
cmin(as[o ? n - p + 1 : p], g[p - 1] + (p > L ? f[p][C % 2 == 0] : f[p + 1][a[p]]) + p - l + r - l);
}
reverse(a + 1, a + n + 1);
}
int z = 0;
L (i, 1, n) {
z = (z + (LL)as[i] * i) % mod;
}
cout << z << '\n';
}
int main () {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
slv();
}
}
// I love WHQ!
詳細信息
Test #1:
score: 0
Wrong Answer
time: 145ms
memory: 24192kb
input:
146645 2 00 2 10 2 01 2 11 3 000 3 100 3 010 3 110 3 001 3 101 3 011 3 111 4 0000 4 1000 4 0100 4 1100 4 0010 4 1010 4 0110 4 1110 4 0001 4 1001 4 0101 4 1101 4 0011 4 1011 4 0111 4 1111 5 00000 5 10000 5 01000 5 11000 5 00100 5 10100 5 01100 5 11100 5 00010 5 10010 5 01010 5 11010 5 00110 5 10110 5...
output:
0 5 4 6 0 14 7 12 8 24 12 26 0 34 19 36 12 40 20 38 17 60 40 58 24 62 42 60 0 69 44 66 27 80 50 83 22 90 60 93 34 87 57 80 33 120 90 123 64 117 87 110 42 123 93 120 67 118 88 129 0 123 86 126 57 128 86 125 40 150 108 147 70 153 111 152 39 168 126 165 88 171 129 170 54 165 123 168 85 154 112 159 58 2...
result:
wrong answer 3rd lines differ - expected: '7', found: '4'