# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42394 | wasyl | Igra (COCI17_igra) | C++11 | 30 ms | 728 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |