#include <bits/stdc++.h>
#ifndef dbg
#define dbg(...)
#endif
#define all(x) begin(x), end(x)
#define rsz(...) resize(__VA_ARGS__)
#define psh(...) push_back(__VA_ARGS__)
#define emp(...) emplace_back(__VA_ARGS__)
#define prt(...) print(cout, __VA_ARGS__)
#define dmp(...) print(cerr, #__VA_ARGS__, '=', __VA_ARGS__)
#define dprt(...) dbg(print(cerr,__VA_ARGS__))
#define ddmp(...) dbg(dmp(__VA_ARGS__))
using namespace std;using ll=long long;
template<typename t>using V=vector<t>;
template<typename t>void print(ostream& os, const t& a){os<<a<<'\n';}
template<typename t, typename... A>void print
(ostream& os, const t& a, A&&... b){os<<a<<' ';print(os, b...);}
string sl, ls;
inline bool foo (const V< int >& tb, const V< int >& z)
{
dbg(
prt("asdj");
for (int i : tb)
cout << i << ' ';
cout << '\n';
for (int i : z)
cout << i << ' ';
cout << '\n';
);
for (int i = 0; i <= min(tb[0], z[1]); ++i)
{
V< int > tb2 = tb;
V< int > z2 = z;
tb2[0] -= i;
z2[1] -= i;
z2[2] -= tb2[0];
if (z2[2] < 0) continue;
tb2[0] = 0;
tb2[1] -= z2[2];
tb2[2] -= z2[1];
if (tb2[1] < 0 or tb2[2] < 0)
continue;
z2[2] = z2[1] = 0;
z2[0] -= tb2[1];
if (z2[0] < 0)
continue;
z2[0] -= tb2[2];
if (z2[0] < 0)
continue;
tb2[1] = tb2[2] = 0;
return true;
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
cin >> ls >> sl;
V< int > tb(3);
for (char c : sl)
++tb[c - 'a'];
V< int > z(3);
for (char c : ls)
++z[c - 'a'];
string res;
for (int i = 0; i < sl.size(); ++i)
{
int v = sl[i] - 'a';
--tb[v];
for (int i = 0; i < 3; ++i)
if (v != i and z[i])
{
--z[i];
if (foo(tb, z))
{
dprt("fd");
res += (char)(i + 'a');
break;
}
++z[i];
}
}
prt(res);
}
Compilation message
igra.cpp: In function 'int main()':
igra.cpp:76:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < sl.size(); ++i)
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
1 ms |
560 KB |
Output is correct |
4 |
Correct |
1 ms |
560 KB |
Output is correct |
5 |
Correct |
1 ms |
560 KB |
Output is correct |
6 |
Correct |
1 ms |
564 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
600 KB |
Output is correct |
9 |
Correct |
30 ms |
600 KB |
Output is correct |
10 |
Correct |
30 ms |
728 KB |
Output is correct |