QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#549309#9229. Juliet Unifies Onesyujianlin#AC ✓0ms3828kbC++171.5kb2024-09-06 14:11:392024-09-06 14:11:40

Judging History

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

  • [2024-09-06 14:11:40]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3828kb
  • [2024-09-06 14:11:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
constexpr int INF=0x3f3f3f3f;
constexpr int MXN=1e6+5;

int dp[55][55];

void solve()
{
    string s;
    cin >> s;
    int n = s.size();
    s = " " + s;
    int cnt1 = 0;
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(s[i] == '0') {
//        	cout << "null : ";
            for(int j = 0; j < i; j ++) if(dp[i - 1][j] != -1)
                dp[i][j] = dp[i - 1][j];
                
//            for(int j = 0; j <= i; j ++) cout << dp[i][j] << ' ';
//        		cout << "\n\n";
            continue;
        }
        
        dp[i][i] = cnt1;
        ++ cnt1;
        dp[i][0] = cnt1;

        // save 1
        for(int j = 1; j < i; j ++) if(dp[i - 1][j] != -1) {
            dp[i][i] = min(dp[i][i], dp[i - 1][j] + i - j - 1);
        }

        // erase 1
        for(int j = 0; j < i; j ++) if(dp[i - 1][j] != -1) {
            if(dp[i][j] != -1) dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
            else dp[i][j] = dp[i - 1][j] + 1;
        }
        
//        for(int j = 0; j <= i; j ++) cout << dp[i][j] << ' ';
//        cout << "\n\n";
    }
    int ans = n;
    for(int i = 0; i <= n; i ++) if(dp[n][i] != -1) ans = min(ans, dp[n][i]);
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int _=1;
    // cin>>_;
    while(_--)
        solve();
    return 0;
}

詳細信息

Test #1:

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

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

11101111111111111101001011110111111110011101010110

output:

11

result:

ok 1 number(s): "11"

Test #3:

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

input:

00000000100000000000100000010001000

output:

3

result:

ok 1 number(s): "3"

Test #4:

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

input:

00000000000000000000000000000000000000000000000000

output:

0

result:

ok 1 number(s): "0"

Test #5:

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

input:

00000000100000000000100000011000

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

11000010100100000011101100000001000100000000000000

output:

8

result:

ok 1 number(s): "8"

Test #7:

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

input:

01100100111011110101010110000100001111110001110001

output:

19

result:

ok 1 number(s): "19"

Test #8:

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

input:

1110101111001

output:

3

result:

ok 1 number(s): "3"

Test #9:

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

input:

1

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

1001

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

11111111111111111111111111111111111111111111111111

output:

0

result:

ok 1 number(s): "0"

Test #12:

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

input:

11111100000000001101010101100011

output:

9

result:

ok 1 number(s): "9"

Test #13:

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

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #14:

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

input:

11011

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

100011011

output:

2

result:

ok 1 number(s): "2"

Test #16:

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

input:

0

output:

0

result:

ok 1 number(s): "0"

Test #17:

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

input:

1010101010011011001101100110011101101011100110110

output:

19

result:

ok 1 number(s): "19"

Test #18:

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

input:

01110100000000111100000011000000000110010001110101

output:

14

result:

ok 1 number(s): "14"

Test #19:

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

input:

01100001000000010000000000010010000100100101001000

output:

9

result:

ok 1 number(s): "9"

Test #20:

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

input:

1101010101010101010101010101010101010101010101011

output:

23

result:

ok 1 number(s): "23"

Extra Test:

score: 0
Extra Test Passed