QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#872457 | #8621. Knapsack | ucup-team008# | TL | 1ms | 3584kb | C++17 | 4.2kb | 2025-01-26 01:49:05 | 2025-01-26 01:49:10 |
Judging History
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(1) cerr
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD
template<class T>
bool updmin(T& a, T b) {
if(b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool updmax(T& a, T b) {
if(b > a) {
a = b;
return true;
}
return false;
}
typedef int64_t ll;
mt19937 g1(0x14004);
ll get_random_int(ll a, ll b) {
return uniform_int_distribution<ll>(a, b)(g1);
}
struct koosaga {
array<ll, 3> sums;
array<vector<int>, 3> sources;
void order() {
for(int i = 0; i < 3; i++) {
for(int j = 0; j + 1 < 3; j++) {
if(sums[j] > sums[j+1]) {
swap(sums[j], sums[j+1]);
swap(sources[j], sources[j+1]);
}
}
}
}
};
void merge(koosaga& ret, koosaga a, koosaga b) {
ret.sums[0] = a.sums[0] + b.sums[2];
ret.sums[1] = a.sums[1] + b.sums[1];
ret.sums[2] = a.sums[2] + b.sums[0];
for(int i = 0; i < 3; i++) {
for(int j: a.sources[i]) ret.sources[i].pb(j);
for(int j: b.sources[i]) ret.sources[2-i].pb(j);
}
ret.order();
}
void solve() {
int n;
cin >> n;
if(n == 6) return void(cout << "ABC.BA\n");
vector<ll> v(n);
for(auto& x: v) cin >> x;
int thresh = n;
while(true) {
vector<koosaga> koos;
for(int i = 0; i < n; i++) {
if(get_random_int(0, n-1) < thresh) {
koosaga koo;
koo.sums[2] = v[i];
koo.sources[2].pb(i);
koos.pb(koo);
}
}
while(sz(koos) > 1) {
sort(all(koos), [&](auto& a, auto& b) -> bool {
return a.sums[2] - a.sums[0] < b.sums[2] - b.sums[0];
});
koosaga koo1 = koos.back(); koos.pop_back();
koosaga koo2 = koos.back(); koos.pop_back();
koosaga cand;
merge(cand, koo1, koo2);
if(cand.sums[0] == cand.sums[2]) {
string ret = "";
for(int i = 0; i < n; i++) ret += ".";
for(int out: cand.sources[0]) ret[out] = 'A';
for(int out: cand.sources[1]) ret[out] = 'B';
for(int out: cand.sources[2]) ret[out] = 'C';
cout << ret << "\n";
return;
}
koos.pb(cand);
}
thresh--;
}
}
// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
6 4 3 8 1 5 4
output:
ABC.BA
result:
ok OK
Test #2:
score: -100
Time Limit Exceeded
input:
10000 997167959139 344481199252 880336470888 152634074578 801642802746 425740396295 408773386884 376579721198 658396628655 317503722503 880971207868 745202647942 998002087506 434268792718 388046761498 176443917727 968016843338 733125908043 536691952768 578717268783 515787375312 454150414369 93569331...