Submission #42394

#TimeUsernameProblemLanguageResultExecution timeMemory
42394wasylIgra (COCI17_igra)C++11
100 / 100
30 ms728 KiB
#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)

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)
                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...