# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
203974 |
2020-02-23T08:39:05 Z |
awlintqaa |
Igra (COCI17_igra) |
C++14 |
|
7 ms |
376 KB |
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 200
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=1e9+7;
const ll inf= 4e18;
const ld pai=acos(-1);
int n ;
string s1,s2;
int NUM [3], num [3];
int RET [3], ret [3];
int check () {
for ( int k =0 ;k <= NUM[1] ; k ++ ) {
for ( int j =0 ;j < 3 ;j ++ ) {
RET [j] = NUM [j ];
ret [j] = num [j ];
}
RET [1] -= min ( k , ret[0]);
ret [0] -= min ( k ,ret[0]);
RET [2] -= min( RET[2] , ret[0]);
int x = min (RET[1] , ret[2] );
RET [1] -= x ;
ret [2] -= x ;
x = min ( RET [0] , ret[2]);
RET [0] -= x;
ret[2] -= x;
if ( RET[0] + RET[2] == ret[1] ) return 1;
}
return 0 ;
}
int main(){
cin >> n ;
cin >> s1 >> s2;
for ( int i =0 ;i < s1.size() ;i ++ ){
num [s1[i]-'a'] ++ ;
}
for ( int i =0; i < s2.size() ;i ++ ){
NUM [s2[i]-'a'] ++ ;
}
string ans = "" ;
for ( int i =0 ;i < n ;i++ ){
int z = 0 ;
for ( int j =0 ;j < 3 ;j ++ ){
if ( s2 [i]-'a' == j || z || num[j] == 0 )C;
NUM [ s2[i] - 'a' ] --;
num [ j ]--;
if ( check() ) {
z=1;
ans += (char) (j+'a');
}
NUM [s2[i] - 'a' ] ++;
num [j] ++;
}
NUM [s2[i]-'a'] -- ;
num [ ans [i] -'a' ] --;
}
cout << ans << endl;
}
Compilation message
igra.cpp: In function 'int main()':
igra.cpp:55:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for ( int i =0 ;i < s1.size() ;i ++ ){
~~^~~~~~~~~~~
igra.cpp:58:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for ( int i =0; i < s2.size() ;i ++ ){
~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
248 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |