QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#309084 | #6128. Flippy Sequence | Alex_Wei | AC ✓ | 262ms | 6948kb | C++14 | 1.5kb | 2024-01-20 14:40:54 | 2024-01-20 14:40:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;
using ull = unsigned long long;
using LL = __int128_t;
#define ppc(x) __builtin_popcount(x)
#define clz(x) __builtin_clz(x)
bool Mbe;
constexpr int mod = 1e9 + 7;
void addt(int &x, int y) {
x += y, x >= mod && (x -= mod);
}
int add(int x, int y) {
return x += y, x >= mod && (x -= mod), x;
}
// ---------- templates above ----------
int n;
string s, t;
void solve() {
cin >> n >> s >> t;
int st = -1, cnt = 0;
for(int i = 0; i < n; i++) {
if(s[i] != t[i]) {
if(st == -1) st = i;
}
else {
if(st != -1) cnt++, st = -1;
}
}
if(st != -1) cnt++;
if(cnt > 2) {
cout << "0\n";
return;
}
if(cnt == 0) {
cout << 1ll * n * (n + 1) / 2 << "\n";
return;
}
if(cnt == 2) {
cout << 6 << "\n";
return;
}
cout << 2 * (n - 1) << "\n";
}
bool Med;
signed main() {
fprintf(stderr, "%.3lf MB\n", (&Mbe - &Med) / 1048576.0);
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ALEX_WEI
FILE* IN = freopen("1.in", "r", stdin);
FILE* OUT = freopen("1.out", "w", stdout);
#endif
int T = 1;
cin >> T;
while(T--) solve();
fprintf(stderr, "%.3lf ms\n", 1e3 * clock() / CLOCKS_PER_SEC);
return 0;
}
/*
g++ a.cpp -o a -std=c++14 -O2 -DALEX_WEI
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4008kb
input:
3 1 1 0 2 00 11 5 01010 00111
output:
0 2 6
result:
ok 3 number(s): "0 2 6"
Test #2:
score: 0
Accepted
time: 262ms
memory: 6948kb
input:
126648 1 0 0 1 1 0 2 01 01 2 01 11 2 10 11 2 11 00 3 011 011 3 010 110 3 011 001 3 111 001 3 001 000 3 101 000 3 011 000 3 111 000 4 1111 1111 4 1110 0110 4 0010 0110 4 1011 0111 4 1001 1011 4 0100 1110 4 0000 0110 4 0111 1001 4 1001 1000 4 1011 0010 4 0001 0100 4 1000 0101 4 0100 0111 4 1101 0110 4...
output:
1 0 3 2 2 2 6 4 4 4 4 6 4 4 10 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 15 8 8 8 8 6 8 8 8 6 6 6 8 6 8 8 8 6 6 6 6 0 6 6 8 6 6 6 8 6 8 8 21 10 10 10 10 6 10 10 10 6 6 6 10 6 10 10 10 6 6 6 6 0 6 6 10 6 6 6 10 6 10 10 10 6 6 6 6 0 6 6 6 0 0 0 6 0 6 6 10 6 6 6 6 0 6 6 10 6 6 6 10 6 10 10 28 12 12 12 12 6 12 12 1...
result:
ok 126648 numbers