답안 #639676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639676 2022-09-11T02:26:36 Z ningia203 Igra (COCI17_igra) C++14
10 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;

long n,cnt1,cnt2,cnt3;
string s,t;
vector<long> ds1;
vector<long> ds2;
vector<long> ds3;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    cin>>s>>t;
    sort(s.begin(),s.end());
    for(long i=0; i<n; i++){
        if(s[i]==t[i]){
            if(s[i]=='a') ds1.push_back(i);
            else if(s[i]=='b') ds2.push_back(i);
            else ds3.push_back(i);
        }
    }
    cnt1=0;
    cnt2=0;
    cnt3=0;
    while(cnt1<ds1.size()){
        if(cnt2<ds2.size()){
            s[ds1[cnt1]]='b';
            s[ds2[cnt2]]='a';
            cnt1++;
            cnt2++;
        }
        else{
            s[ds1[cnt1]]='c';
            s[ds3[cnt3]]='a';
            cnt1++;
            cnt3++;
        }
    }
    while(cnt2<ds2.size()){
         s[ds2[cnt2]]='c';
         s[ds3[cnt3]]='b';
         cnt2++;
         cnt3++;
    }
    while(cnt3<ds3.size()){
        if(cnt2>0){
            cnt2--;
            swap(s[ds3[cnt3]],s[ds2[cnt2]]);
        }
        else{
            cnt1--;
            swap(s[ds3[cnt3]],s[ds1[cnt1]]);
        }
        cnt3++;
    }
    cout<<s;
    return 0;
}

Compilation message

igra.cpp: In function 'int main()':
igra.cpp:24:15: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     while(cnt1<ds1.size()){
      |           ~~~~^~~~~~~~~~~
igra.cpp:25:16: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         if(cnt2<ds2.size()){
      |            ~~~~^~~~~~~~~~~
igra.cpp:38:15: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     while(cnt2<ds2.size()){
      |           ~~~~^~~~~~~~~~~
igra.cpp:44:15: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     while(cnt3<ds3.size()){
      |           ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct