답안 #918297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918297 2024-01-29T14:45:40 Z _VIBE Team Contest (JOI22_team) C++17
0 / 100
1 ms 348 KB
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;

#define int long long
#define endl '\n'

void Excuse_Me(int TC)
{
    
    int n;
    cin>>n;
    
    vector<int> mx(3,0);
    priority_queue<pair<int,pair<int,int>>> pq;
    
    set<pair<int,int>> s[3];
    
    vector<vector<int>> g(n,vector<int>(3));
    
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            int x;
            cin>>x;
            pq.push({x,{j,i}});
            mx[j]=max(mx[j],x);
            g[i][j]=x;
        }
    }
    
    while(!pq.empty()){
        pair<int,pair<int,int>> p=pq.top();
        pq.pop();
        int i=p.second.second,j=p.second.first;
        
        bool poss=true;
        
        for(int k=0;k<3;k++){
            if(k==j) continue;
            if(g[i][k]==mx[k]) poss=false;
        }
        
        if(poss) s[j].insert({p.first,i});
        
    }
    
    
    int ans=-1;
    
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            
            if(i==j) continue;
            
            int k=3-i-j;
            
            if(s[i].empty() or s[j].empty() or s[k].empty()) continue;
            
            //priority order is i then j then k
            
            //get last element of i
            
            
            pair<int,int> p=*s[i].rbegin();
            
            int val1=p.first;
        
            int val2=-1;
            
            auto it=s[j].end();
            it--;
            
            pair<int,int> q;
            
            while(it!=s[j].begin()){
                q=*it;
                if(q.first>g[p.second][j]){
                    val2=q.first;break;
                }
                it--;
            }
            
            if(val1==-1){
                q=*it;
                if(q.first>g[p.second][j] and p.first>g[q.second][i]){
                    val2=q.first;
                }
            }
            
            
            
            if(val2==-1) continue;
            
            int val3=-1;
            
            it=s[k].end();
            it--;
            
            pair<int,int> r;
            
            while(it!=s[k].begin()){
                r=*it;
                if(r.first>max(g[p.second][k],g[q.second][k]) and p.first>max(g[q.second][i],g[r.second][i]) and q.first>max(g[p.second][j],g[r.second][j])){
                    ans=max(ans,p.first+r.first+q.first);break;
                }
                it--;
            }
            
            r=*it;
            if(r.first>max(g[p.second][k],g[q.second][k]) and p.first>max(g[q.second][i],g[r.second][i]) and q.first>max(g[p.second][j],g[r.second][j])){
                ans=max(ans,p.first+r.first+q.first);break;
            }            
            
        }
    }
    
    cout<<ans;
  
    
    
   
}
 
signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    freopen("error.txt","w",stderr);
    int Tc=1;
    // cin>>Tc;
 
    for(int tc=1;tc<=Tc;tc++)
    {
        Excuse_Me(tc);
    }
   
    return 0;
}

Compilation message

team.cpp: In function 'void Excuse_Me(long long int)':
team.cpp:99:17: warning: unused variable 'val3' [-Wunused-variable]
   99 |             int val3=-1;
      |                 ^~~~
team.cpp: In function 'int main()':
team.cpp:132:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |     freopen("error.txt","w",stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -