이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#pragma gcc optimize('ofast','unroll-loops')
#define endl '\n'
#define ff first
#define ss second
#define pb emplace_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(a,b,c) for(int a=b;a<c;a++)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
const ll maxn = 150005;
const ll maxm = 200005;
const ll mod = 1000000007;
void solve(){
int n;
pii a[maxn], b[maxn], c[maxn];
int tmpa[maxn], tmpb[maxn], tmpc[maxn];
bitset<maxn> check;
cin >> n;
rep(i,0,n) cin >> a[i].ff >> b[i].ff >> c[i].ff, a[i].ss = b[i].ss = c[i].ss = i;
rep(i,0,n) tmpa[i] = a[i].ff, tmpb[i] = b[i].ff, tmpc[i] = c[i].ff;
sort(a,a+n), sort(b,b+n), sort(c,c+n);
int at = n-1, bt = n-1, ct = n-1;
while(1){
if(at<0 || bt<0 || ct<0){
cout << -1 << endl;
return;
}
//cout << endl << at << ' ' << bt << ' ' << ct << ' ' << endl;
if(tmpb[a[at].ss]==b[bt].ff || tmpc[a[at].ss]==c[ct].ff) check[a[at].ss] = 1;
else if(tmpa[b[bt].ss]==a[at].ff || tmpc[b[bt].ss]==c[ct].ff) check[b[bt].ss] = 1;
else if(tmpa[c[ct].ss]==a[at].ff || tmpb[c[ct].ss]==b[bt].ff) check[c[ct].ss] = 1;
else{
cout << a[at].ff+b[bt].ff+c[ct].ff << endl;
return;
}
while(at>-1 && check[a[at].ss]) at--;
while(bt>-1 && check[b[bt].ss]) bt--;
while(ct>-1 && check[c[ct].ss]) ct--;
}
}
int main(){
//freopen("input.txt","r",stdin);
//freopen("sol.txt","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
team.cpp:4: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
4 | #pragma gcc optimize('ofast','unroll-loops')
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |