QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140564#6628. Flip it and Stick itwsyear1 2ms4560kbC++143.2kb2023-08-16 10:57:072023-08-16 10:57:08

Judging History

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

  • [2023-08-16 10:57:08]
  • 评测
  • 测评结果:1
  • 用时:2ms
  • 内存:4560kb
  • [2023-08-16 10:57:07]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

const int N = 200010;

int n, m, a[N];
string str;
priority_queue<int> q;

int A(int x) {
  int cnt = 0;
  rep (i, 1, n) if (a[i] == x) cnt++;
  return cnt ? -1 : 0;
}

int AA(int x) {
  int cnt = 0;
  rep (i, 1, n) if (a[i] == x) cnt++;
  if (cnt > (n + 1) / 2) return -1;
  for (int l = 1, r; l <= n; l = r + 1) {
    if (a[l] != x) r = l;
    else {
      r = l;
      while (r < n && a[r + 1] == x) r++;
      cnt--;
    }
  }
  return cnt;
}

int AB(int x) {
  int cnt = 0;
  for (int r = n - 1, l; r >= 1; r = l - 1) {
    if (a[r] != x) l = r;
    else {
      l = r;
      while (l > 1 && a[l - 1] == x) l--;
      cnt++;
    }
  }
  return cnt;
}

int AAB(int x) {
  int cnt = 0;
  for (int r = n - 1, l; r >= 1; r = l - 1) {
    if (a[r] != x) l = r;
    else {
      l = r;
      while (l > 1 && a[l - 1] == x) l--;
      cnt += (r > l);
    }
  }
  return cnt;
}

int ABA(int x) {
  int cnt = 0;
  for (int r = n, l; r >= 1; r = l - 1) {
    if (a[r] == x) l = r;
    else {
      l = r;
      while (l > 1 && a[l - 1] != x) l--;
      cnt += (r == l && l > 1 && r < n);
    }
  }
  return (cnt + 1) / 2;
}

int AAA(int x) {
  int cnt = 0;
  rep (i, 1, n) if (a[i] == x) cnt++;
  if (cnt > n / 3 * 2 + n % 3) return -1;
  int c1 = 0, c2 =0;
  while (!q.empty()) q.pop();
  for (int l = 1, r; l <= n; l = r + 1) {
    r = l;
    while (r < n && a[r + 1] == a[r]) r++;
    if (a[l] != x) c2 += r - l;
    else if (l == r) c1 += 1;
    else if (r - l > 1) q.push(r - l - 1);
  }
  int ans = 0;
  while (!q.empty()) {
    int x = q.top();
    q.pop();
    if (c2) {
      if (x >= 2) c2--, x -= 2;
      else c2--, c1++, x = 0;
    } else {
      c1--, x -= 1;
    }
    ans++;
    if (x != 0) q.push(x);
  }
  return ans;
}

void work() {
  cin >> str, n = str.length();
  rep (i, 1, n) a[i] = str[i - 1] - '0';
  cin >> str, m = str.length();
  if (m == 1) cout << A(str[0] - '0') << '\n';
  else if (m == 2 && str[0] == str[1]) cout << AA(str[0] - '0') << '\n';
  else if (m == 2 && str[0] != str[1]) cout << AB(str[0] - '0') << '\n';
  else if (str[0] == str[1] && str[1] != str[2]) cout << AAB(str[0] - '0') << '\n';
  else if (str[0] != str[1] && str[1] == str[2]) reverse(a + 1, a + n + 1), cout << AAB(str[2] - '0') << '\n';
  else if (str[0] == str[2] && str[0] != str[1]) cout << ABA(str[0] - '0') << '\n';
  else if (str[0] == str[1] && str[1] == str[2]) cout << AAA(str[0] - '0') << '\n';
}

int main() {
  // freopen("shin.in", "r", stdin);
  // freopen("shin.out", "w", stdout);
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  int t = 1;
  while (t--) work();
}

詳細信息

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 1ms
memory: 3540kb

input:

1
0

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3484kb

input:

1
1

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 2ms
memory: 4392kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 2ms
memory: 4560kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 2ms
memory: 4384kb

input:

101001000011101010101001001010010110111111001100110001111101111110110110101011111010001101111001101101010111101100000110001110001100000101111100000110111110001010101101101110001000011010000101000110110010110110100001110001111001010000000010000000101000000100110011101110100111111101111111111110010101...

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

score: 0
Accepted
time: 0ms
memory: 4556kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 2ms
memory: 4364kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

-1

result:

ok 1 number(s): "-1"

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 3
Accepted
time: 1ms
memory: 3476kb

input:

0
01

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 1ms
memory: 3480kb

input:

0
10

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 1ms
memory: 3484kb

input:

01
01

output:

1

result:

ok 1 number(s): "1"

Test #11:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

01
10

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

1010101010
10

output:

5

result:

ok 1 number(s): "5"

Test #13:

score: -3
Wrong Answer
time: 0ms
memory: 4408kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1

result:

wrong answer 1st numbers differ - expected: '0', found: '1'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #40:

score: 5
Accepted
time: 1ms
memory: 3484kb

input:

11
011

output:

0

result:

ok 1 number(s): "0"

Test #41:

score: 0
Accepted
time: 1ms
memory: 3388kb

input:

0
110

output:

0

result:

ok 1 number(s): "0"

Test #42:

score: 0
Accepted
time: 1ms
memory: 3648kb

input:

01
100

output:

0

result:

ok 1 number(s): "0"

Test #43:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

110
110

output:

1

result:

ok 1 number(s): "1"

Test #44:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

010
001

output:

0

result:

ok 1 number(s): "0"

Test #45:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

001001001001
001

output:

4

result:

ok 1 number(s): "4"

Test #46:

score: 0
Accepted
time: 2ms
memory: 4460kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #47:

score: -5
Wrong Answer
time: 2ms
memory: 4408kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

1

result:

wrong answer 1st numbers differ - expected: '0', found: '1'

Subtask #5:

score: 0
Wrong Answer

Test #53:

score: 5
Accepted
time: 0ms
memory: 3496kb

input:

11
011

output:

0

result:

ok 1 number(s): "0"

Test #54:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

01
100

output:

0

result:

ok 1 number(s): "0"

Test #55:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

011
011

output:

1

result:

ok 1 number(s): "1"

Test #56:

score: 0
Accepted
time: 1ms
memory: 3648kb

input:

010
100

output:

0

result:

ok 1 number(s): "0"

Test #57:

score: 0
Accepted
time: 1ms
memory: 3476kb

input:

0
010

output:

0

result:

ok 1 number(s): "0"

Test #58:

score: 0
Accepted
time: 1ms
memory: 3496kb

input:

10
101

output:

0

result:

ok 1 number(s): "0"

Test #59:

score: 0
Accepted
time: 1ms
memory: 3492kb

input:

010
010

output:

1

result:

ok 1 number(s): "1"

Test #60:

score: 0
Accepted
time: 1ms
memory: 3436kb

input:

000
101

output:

0

result:

ok 1 number(s): "0"

Test #61:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

001001001001
100

output:

3

result:

ok 1 number(s): "3"

Test #62:

score: 0
Accepted
time: 2ms
memory: 4388kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #63:

score: -5
Wrong Answer
time: 0ms
memory: 4392kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

1

result:

wrong answer 1st numbers differ - expected: '0', found: '1'

Subtask #6:

score: 0
Skipped

Dependency #4:

0%