답안 #155159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155159 2019-09-26T17:20:03 Z phillip Igra (COCI17_igra) C++14
10 / 100
3 ms 376 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int dp[5009][3];
int n,a[5009];
int x[5009];
string s;
int main()
{
    cin>>n>>s;
    for(int i=0;i<n;i++)x[s[i]-'a']++;
    cin>>s;
    for(int i=n-1;i>=0;i--)
    {
        for(int j=0;j<3;j++)dp[i][j]=dp[i-1][j];
        dp[i][s[i]-'a']++;
    }
    for(int i=0;i<n;i++)
    {
        int num=s[i]-'a';
        if(i==n-1)
        {
            for(int j=0;j<3;j++)
            {
                if(x[j])a[i]=j;
            }
            break;
        }
        for(int j=0;j<3;j++)
        {
            if(j==num)continue;
            if(x[j]==0)continue;
            int k;
            if(num==0)
            {
                if(j==1)k=2;
                else k=1;
            }
            if(num==1)
            {
                if(j==2)k=0;
                else k=2;
            }

            if(num==2)
            {
                if(j==1)k=0;
                else k=1;
            }
            if(x[num]+x[j]>dp[i+1][k])
            {
                x[j]--;
                a[i]=j;
                break;
            }
        }
        //for(int i=0;i<3;i++)cout<<x[i]<<" ";cout<<"\n";
    }
    for(int i=0;i<n;i++)cout<<char('a'+a[i]);
}
/*
6
abcaaa
aabbbb
*/

Compilation message

igra.cpp: In function 'int main()':
igra.cpp:50:37: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if(x[num]+x[j]>dp[i+1][k])
                            ~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Incorrect 2 ms 256 KB Output isn't correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Incorrect 2 ms 256 KB Output isn't correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Incorrect 3 ms 376 KB Output isn't correct
10 Incorrect 3 ms 376 KB Output isn't correct