QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#401105#5577. Alchemyjoelgun14WA 0ms3824kbC++141.0kb2024-04-27 22:00:402024-04-27 22:00:41

Judging History

This is the latest submission verdict.

  • [2024-04-27 22:00:41]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3824kb
  • [2024-04-27 22:00:40]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool correct[n];
  for(int i = 0; i < n; ++i) {
    if(s[i] == s[n - i - 1])
      correct[i] = true;
    else
      correct[i] = false;
  }
  if(s.size() <= 3) {
    if(correct[0])
      cout << 0 << endl;
    else
      cout << 1 << endl;
    return 0;
  }
  int dp[n][2];
  // utk posisi 0
  if(correct[0]) {
    dp[0][1] = 0;
    dp[0][0] = 1e9;
  }
  else {
    dp[0][1] = 1e9;
    dp[0][0] = 0;
  }
  for(int i = 1; i < n / 2; ++i) {
    if(correct[i]) {
      // SB -> BS -> BB
      dp[i][1] = min(dp[i - 1][1], dp[i - 1][0] + 2);
      // BB -> SS -> BS
      // SB -> BS
      dp[i][0] = min(dp[i - 1][1] + 2, dp[i - 1][0] + 1);
    }
    else {
      // 
      dp[i][1] = min(dp[i - 1][1] + 2, dp[i - 1][0] + 1);
      dp[i][0] = min(dp[i - 1][1], dp[i - 1][0] + 1);
    }
    //cout << dp[i][0] << " " << dp[i][1] << endl;
  }
  cout << dp[n / 2 - 1][1] << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

ioi

output:

0

result:

ok single line: '0'

Test #2:

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

input:

noi

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3604kb

input:

ctsc

output:

2

result:

wrong answer 1st lines differ - expected: '1', found: '2'