Submission #397630

# Submission time Handle Problem Language Result Execution time Memory
397630 2021-05-02T15:37:58 Z victoriad Igra (COCI17_igra) C++14
40 / 100
2 ms 332 KB
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin>>n;
   string s,l;
   cin>>l;
   cin>>s;
   vector<int>d(n,0);
   for(int i=0;i<n;i++){
     if(l[i]=='a'){
       d[0]++;
     }
     else if(l[i]=='b'){
       d[1]++;
     }
     else{
       d[2]++;
     }
   }
   vector<char>r;
   for(int i=0;i<n;i++){
     if(s[i]=='a'){
       if(d[1]>0){
         r.push_back('b');
         d[1]--;
       }
       else if(d[2]>0){
         r.push_back('c');
         d[2]--;
       }
       else{
         for(int k=i-1;k>=0;k--){
          if(r[k]=='b'||r[k]=='c'){
            if(s[k]!='a'){
              r.push_back(r[k]);
              r[k]='a';
              break;
            }
          }
         }
       }
     }
     else if(s[i]=='b'){
       if(d[0]>0){
         r.push_back('a');
         d[0]--;
       }
       else if(d[2]>0){
         r.push_back('c');
         d[2]--;
       }
       else{
         for(int k=i-1;k>=0;k--){
          if(r[k]=='a'||r[k]=='c'){
            if(s[k]!='b'){
              r.push_back(r[k]);
              r[k]='b';
              break;
            }
          }
         }
       }
     }
     else if(s[i]=='c'){
       if(d[0]>0){
         r.push_back('a');
         d[0]--;
       }
       else if(d[1]>0){
         r.push_back('b');
         d[1]--;
       }
       else{
         for(int k=i-1;k>=0;k--){
          if(r[k]=='a'||r[k]=='b'){
            if(s[k]!='c'){
              r.push_back(r[k]);
              r[k]='c';
              break;
            }
          }
         }
       }
     }
     }
   for(int i=0;i<n;i++){
     cout<<r[i];
   }
   
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Incorrect 1 ms 204 KB Output isn't correct
9 Incorrect 2 ms 332 KB Output isn't correct
10 Incorrect 2 ms 332 KB Output isn't correct