이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);
void solve(){
int n;
cin >> n;
vector<pair<int,int>> a , b , c;
int arr[n][3];
for(int i = 0; i < n; i++){
int x , y, z;
cin >> x >> y >> z;
a.pb(mp(x,i));
b.pb(mp(y,i));
c.pb(mp(z,i));
arr[i][0] = x;
arr[i][1] = y;
arr[i][2] = z;
}
sort(all(a),greater<>());
sort(all(b) , greater<>());
sort(all(c), greater<>());
int i = 0 , j = 0 , k = 0;
bool vis[n];
memset(vis,0,sizeof vis);
int cnt = 1;
while(cnt != 0){
cnt = 0;
while(i < (int)a.size() && (arr[a[i].vs][1] == b[j].vf || arr[a[i].vs][2] == c[k].vf)){
vis[a[i].vs] = 1;
while(i < (int)a.size() && vis[a[i].vs])i++;
while(j < (int)b.size() && vis[b[j].vs])j++;
while(k < (int)c.size() && vis[c[k].vs])k++;
cnt=1;
}
while(j < (int)b.size() && (arr[b[j].vs][0] == a[i].vf || arr[b[j].vs][2] == c[k].vf)){
vis[b[j].vs] = 1;
while(i < (int)a.size() && vis[a[i].vs])i++;
while(j < (int)b.size() && vis[b[j].vs])j++;
while(k < (int)c.size() && vis[c[k].vs])k++;
cnt=1;
}
while(k < (int)c.size() && (arr[c[k].vs][1] == b[j].vf || arr[c[k].vs][0] == a[i].vf)){
vis[c[k].vs] = 1;
while(i < (int)a.size() && vis[a[i].vs])i++;
while(j < (int)b.size() && vis[b[j].vs])j++;
while(k < (int)c.size() && vis[c[k].vs])k++;
cnt=1;
}
}
if(i < n && j < n && k < n){
cout << a[i].vf + b[j].vf + c[k].vf << '\n';
}
else cout << -1 << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# | 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... |