제출 #1303158

#제출 시각아이디문제언어결과실행 시간메모리
1303158nhinconmemayTeam Contest (JOI22_team)C++20
26 / 100
1495 ms8068 KiB
#include <bits/stdc++.h> using namespace std ; #define ll long long #define FOR(i ,a , b) for(int i = a ; i <= b ; i++) #define name "teamcontest" #define pb push_back #define all(a) a.begin() , a.end() #define bit(mask , i) ((mask >> i) & 1) #define fi first #define se second const ll N = 1e6 + 5 ; const ll LOG = 20 ; const ll MOD = 1e9 + 7 ; ll n ; struct Point { ll a , b , c ; }x[N]; bool cmd(Point x , Point y) { if(x.a != y.a) return x.a < y.a ; if(x.b != y.b) return x.b < y.b ; return x.c < y.c ; } struct fenwick { ll f[500005] , n ; void init(int _n) { n = _n ; memset(f , -1 , sizeof f) ; } void update(ll i , ll x) { while(i < n) { f[i] = max(f[i] , x); i += i & (-i) ; } } ll getmax(ll i) { ll res = -1 ; while(i) { res = max(res , f[i]) ; i -= i &(-i) ; } return res ; } }fen; vector<ll> rrhB ; #define lo lower_bound namespace sub2 { ll getval(ll x) { return lo(all(rrhB) , x) - rrhB.begin() + 1 ; } void sol() { FOR(i , 1 , n) { rrhB.push_back(x[i].b) ; rrhB.push_back(x[i].b - 1) ; } sort(all(rrhB)) ; rrhB.erase(unique(all(rrhB)) , rrhB.end()) ; ll ans = -1 ; // FOR(i ,1, n) cout << x[i].a <<' '<< x[i].b <<' '<< x[i].c <<'\n'; FOR(i ,3 ,n) { ll cost = -1 ; fen.init(150000) ; FOR(j , 1, i - 1) { if(x[i].a == x[j].a) continue ; if(j == 1) { // cout << "update" << x[j].b <<"->"<< x[j].c <<'\n'; fen.update(getval(x[j].b) , x[j].c) ; continue ; } if(x[j].b > x[i].b) { ll C = fen.getmax(getval(x[j].b - 1)) ; // cout << x[j].b - 1 <<'\n'; if(C > x[j].c && C > x[i].c) cost = max(cost , x[i].a + x[j].b + fen.getmax(getval(x[j].b - 1))) ; } fen.update(getval(x[j].b) , x[j].c) ; } ans = max(ans , cost) ; } cout << ans ; } bool checksub() { return n <= 4000 ; } } namespace sub4 { bool f[21][21][21] ; Point X[N] ; void sol() { FOR(i , 1, n) f[x[i].a][x[i].b][x[i].c] = 1 ; ll cnt = 0; FOR(i ,1, 20) FOR(j ,1,20) FOR(z , 1 , 20) if(f[i][j][z]) X[++cnt] = {i , j , z} ; ll ans = -1 ; sort(X + 1 , X + cnt + 1 , cmd) ; // cout << cnt <<'\n'; // FOR(i , 1,cnt) cout << X[i].a <<' '<< X[i].b <<' '<< X[i].c <<'\n'; FOR(i ,3 ,cnt) { ll cost = -1 ; fen.init(100) ; FOR(j , 1, i - 1) { if(X[i].a == X[j].a) continue ; if(j == 1) { // cout << "update" << x[j].b <<"->"<< x[j].c <<'\n'; fen.update(X[j].b , X[j].c) ; continue ; } if(X[j].b > X[i].b) { ll C = fen.getmax(X[j].b - 1) ; // cout << x[j].b - 1 <<'\n'; if(C > X[j].c && C > X[i].c) cost = max(cost , X[i].a + X[j].b + fen.getmax(X[j].b - 1)) ; } fen.update(X[j].b , X[j].c) ; } ans = max(ans , cost) ; } cout << ans ; } bool checksub() { FOR(i , 1,n) { if(x[i].a > 20 || x[i].b > 20 || x[i].c > 20) return false ; } return true ; } } int main() { ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; if(fopen(name".inp" ,"r")) { freopen(name".inp" , "r" , stdin) ; freopen(name".out" , "w" , stdout) ; } cin >> n ; FOR(i ,1 , n) cin >> x[i].a >> x[i].b >> x[i].c ; sort(x + 1 , x + n + 1 , cmd) ; if(sub2::checksub()) sub2::sol() ; else sub4::sol() ; }

컴파일 시 표준 에러 (stderr) 메시지

team.cpp: In function 'int main()':
team.cpp:170:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  170 |         freopen(name".inp" , "r" , stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:171:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  171 |         freopen(name".out" , "w" , stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...