QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#732397#9565. Birthday Giftqinglu09#WA 0ms3560kbC++231.5kb2024-11-10 14:22:462024-11-10 14:22:47

Judging History

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

  • [2024-11-10 14:22:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3560kb
  • [2024-11-10 14:22:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define endl '\n'
#define debug(x) cout<<#x<<": "<<x<<endl
const int N=2e5+10;

void solve()
{
    int n;
    string s;
    cin >> s;
    n = s.size();
    s = '|' + s;
    int dp[n + 5][2];
    rep(i, 0, n)
    {
        rep(j, 0, 1)
        {
            dp[i][j] = 1e9;
        }
    }
    dp[0][0] = 0;
    dp[0][1] = 0;
    rep(i, 1, n)
    {
        if(s[i] == '0' || s[i] == '2')
        {
            if(dp[i - 1][0])
            {
                dp[i][1] = min(dp[i][1], dp[i - 1][0] - 1);
            }
            else
            {
                dp[i][0] = min(dp[i][0], 1);
            }
            dp[i][0] = min(dp[i - 1][1] + 1, dp[i][0]);
        }
        if(s[i] == '1' || s[i] == '2')
        {
            if(dp[i - 1][1])
            {
                dp[i][0] = min(dp[i][0], dp[i - 1][1] - 1);
            }
            else
            {
                dp[i][1] = min(dp[i][1], 1);
            }
            dp[i][1] = min(dp[i - 1][0] + 1, dp[i][1]);
        }
    }
    cout << min(dp[n][0], dp[n][1]) << endl;
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
// #ifndef  ONLINEJUDGE
//     freopen("test.in","r",stdin);
//     freopen("test.out","w",stdout);
// #endif
    int T;
    cin>>T;
    while(T--)
    {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3560kb

input:

5
0110101
01020102
0000021111
1012121010
0100202010

output:

3
4
0
6
2

result:

wrong answer 5th numbers differ - expected: '0', found: '2'