답안 #918307

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918307 2024-01-29T15:11:37 Z _VIBE Team Contest (JOI22_team) C++17
0 / 100
2000 ms 38212 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;

    auto check=[&](pair<int,int> p,int i,int j,int k)->bool{
                
            int val=-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] and p.first>g[q.second][i]){
                    val=q.first;break;
                }
                it--;
            }
            
            if(val==-1){
                q=*it;
                if(q.first>g[p.second][j] and p.first>g[q.second][i]){
                    val=q.first;
                }
                else return false;
            }
            
            
            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);return true;
                }
                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);return true;
            }     
            return false; 
    };
    
    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
            
            auto it=s[i].end();
            it--;
            
            while(it!=s[i].begin()){
                if(check(*it,i,j,k)) break;
                it--;
            }
            
            check(*it,i,j,k);
            
            
        }
    }
    
    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 'int main()':
team.cpp:138:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  138 |     freopen("error.txt","w",stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Incorrect 3 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Incorrect 3 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 254 ms 38212 KB Output is correct
12 Execution timed out 2069 ms 27104 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 254 ms 38212 KB Output is correct
12 Execution timed out 2069 ms 27104 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 254 ms 38212 KB Output is correct
12 Execution timed out 2069 ms 27104 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 254 ms 38212 KB Output is correct
12 Execution timed out 2069 ms 27104 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Incorrect 3 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -