Submission #917367

#TimeUsernameProblemLanguageResultExecution timeMemory
917367cig32Team Contest (JOI22_team)C++17
100 / 100
142 ms23760 KiB
#include "bits/stdc++.h" using namespace std; #define int long long #define double long double const int MAXN = 3e5 + 10; const int MOD = 1e9 + 7; mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } int bm(int b, int p) { if(p==0) return 1 % MOD; int r = bm(b, p >> 1); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } int inv(int b) { return bm(b, MOD-2); } int fastlog(int x) { return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1); } void printcase(int i) { cout << "Case #" << i << ": "; } static void run_with_stack_size(void (*func)(void), size_t stsize) { char *stack, *send; stack = (char *)malloc(stsize); send = stack + stsize - 16; send = (char *)((uintptr_t)send / 16 * 16); asm volatile( "mov %%rsp, (%0)\n" "mov %0, %%rsp\n" : : "r"(send)); func(); asm volatile("mov (%0), %%rsp\n" : : "r"(send)); free(stack); } void solve(int tc) { int n; cin >> n; int x[n+1], y[n+1], z[n+1], ban[n+1]; priority_queue<pair<int,int>> xx,yy,zz; for(int i=1; i<=n; i++) { cin >> x[i] >> y[i] >> z[i]; xx.push({x[i],i}); yy.push({y[i],i}); zz.push({z[i],i}); ban[i] = 0; } while(1) { while(xx.size() && ban[xx.top().second]) xx.pop(); while(yy.size() && ban[yy.top().second]) yy.pop(); while(zz.size() && ban[zz.top().second]) zz.pop(); if(xx.empty() || yy.empty() || zz.empty()) break; pair<int,int> xt= xx.top(); pair<int,int> yt= yy.top(); pair<int,int> zt= zz.top(); vector<int> bruhs = {xt.second, yt.second, zt.second}; vector<int> bad; for(int w: bruhs) { int cnt = (x[w] == xt.first) + (y[w] == yt.first) + (z[w] == zt.first); if(cnt > 1) bad.push_back(w); } if(bad.size()) { for(int w: bad) { ban[w] = 1; } continue; } cout << xt.first + yt.first + zt.first << '\n'; return; } cout << "-1\n"; return; } void uwu() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i=1; i<=t; i++) solve(i); } int32_t main() { #ifdef ONLINE_JUDGE uwu(); #endif #ifndef ONLINE_JUDGE run_with_stack_size(uwu, 1024 * 1024 * 1024); // run with a 1 GiB stack #endif } /* g++ E.cpp -std=c++17 -O2 -o E ./E < input.txt */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...