QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#326421#6128. Flippy SequenceLainAC ✓70ms7128kbC++23996b2024-02-13 01:24:332024-02-13 01:24:33

Judging History

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

  • [2024-02-13 01:24:33]
  • 评测
  • 测评结果:AC
  • 用时:70ms
  • 内存:7128kb
  • [2024-02-13 01:24:33]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int tt;
  cin >> tt;
  while(tt--) {
    int n;
    string s, t;
    cin >> n >> s >> t;
    vector<bool> changed(n);
    for (int i =0; i < n; i++) {
      changed[i] = s[i] != t[i];
    }
    vector<pair<int, int>> runs;
    int l = -1, r = -1;
    for (int i =0; i < n; i++) {
      if (changed[i]) {
        if (l == -1) l = i;
      } else {
        if (l != -1) {
          runs.push_back({l, i-1});
        }
        l = r = -1;
      }
    }
    if (l != -1) {
      runs.push_back({l, n-1});
    }
    if (runs.size() == 0) {
      cout << (int64_t(n) * (n+1))/2 << '\n';
    } else if (runs.size() == 2){
      cout << 6 << '\n';
    } else if (runs.size() == 1) {
      auto& [l, r] = runs[0];
      int64_t ans =  2 * (l + n - 1 -r) + 2*(r-l);
      cout << ans << '\n';
    } else {
      cout << 0 << '\n';
    }
  }
}


详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

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: 70ms
memory: 7128kb

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