QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#143030 | #6667. Prosjek | penguinman# | 0 | 0ms | 0kb | C++17 | 2.6kb | 2023-08-20 12:00:53 | 2024-07-04 01:49:45 |
answer
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define ln "\n"
#define pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define all(a) a.begin(),a.end()
constexpr ll inf = (1ll<<60);
constexpr ll mod = 1e9+7;
constexpr ll mul = 23;
void dec(std::map<ll,ll> &mem, ll el){
mem[el]--;
if(mem[el] == 0) mem.erase(el);
}
void solve(){
ll N; cin >> N;
constexpr ll maxi = 11;
vi cnt(maxi);
vi A(N);
rep(i,0,N) cin >> A[i];
rep(i,0,N) cnt[A[i]]++;
vi mul(maxi+1,1);
rep(i,0,maxi) mul[i+1] = mul[i]*3;
ll M = mul[maxi];
vi dp(M,-1);
vi a, b;
std::function<bool(ll)> dfs = [&](ll now){
if(dp[now] != -1) return bool(dp[now]);
vi v(maxi);
ll nvv = now;
rep(i,0,maxi){
v[i] = nvv%3;
nvv /= 3;
}
ll total = 0;
rep(i,0,maxi){
total += v[i];
}
dp[now] = 1;
if(total == 1) return true;
rep(i,0,maxi){
if(v[i] == 2){
bool flag = dfs(now-mul[i]);
if(flag){
a.pb(i);
b.pb(i);
dp[now] = 1;
return true;
}
}
rep(j,i+1,maxi){
if(v[i] == 0 || v[j] == 0) continue;
if((i+j)%2) continue;
ll k = (i+j)/2;
bool flag = dfs(now-mul[i]-mul[j]+mul[k]);
if(flag){
a.pb(i);
b.pb(j);
dp[now] = 1;
return true;
}
}
}
dp[now] = 0;
return false;
};
ll nval = 0;
rep(i,0,maxi){
nval += std::min(2ll, cnt[i])*mul[i];
}
if(dfs(nval)){
rep(i,0,maxi){
rep(j,2,cnt[i]){
a.pb(i);
b.pb(i);
}
}
reverse(all(a));
reverse(all(b));
assert(a.size() == N-1);
rep(i,0,N-1) cout << a[i] << " " << b[i] << ln;
}
else cout << -1 << ln;
}
int main(){
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
ll T; cin >> T;
while(T--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
99 4 739880851158065302 19206582949872932 883064254701115295 222072661880779376 7 148399819461615003 209088712310207988 53191076581680214 445068618251612752 230505279594622109 115754892157516718 804173775829453588 2 77979357045500669 41693388829622019 3 341612949433488278 609808714829036935 19994167...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #16:
score: 0
Runtime Error
input:
100 3 3 3 2 3 4 1 1 4 1 3 4 4 6 4 4 2 3 1 2 4 0 2 1 4 3 0 2 0 7 3 3 1 1 3 4 0 2 0 4 4 1 4 2 3 7 4 0 0 3 2 3 4 4 4 2 0 3 7 0 2 2 1 4 2 4 7 3 0 3 1 2 0 3 4 4 3 1 4 6 2 3 0 1 3 4 5 1 4 0 3 4 5 4 2 0 4 2 3 0 1 2 6 4 1 4 2 0 4 7 4 2 4 3 1 3 1 4 1 4 4 0 2 1 1 6 0 3 3 0 0 4 7 4 3 0 3 3 3 4 4 4 1 1 3 6 2 0 ...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #34:
score: 0
Runtime Error
input:
100000 5 846784256447769304 457696478728961702 128469521648960690 597630796847754190 104256763714529164 5 658897822238868978 472135077337628566 399538027669313322 622703684108675696 425723088635325654 5 917704960887390986 140817562615382054 877934664521057998 782212806618666818 616380973421914538 8 ...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #46:
score: 0
Runtime Error
input:
100 211957 911918942087402387 344230223346742784 16289402153237664 528890583619159010 886281719684850237 865484734102017297 321851390502278959 754268375474197153 237414161302130571 135637002716682378 824412491959977735 162505521049217610 246319278060116103 666703181591704279 650875500699154233 96397...