제출 #942701

#제출 시각아이디문제언어결과실행 시간메모리
942701Tyx20193단 점프 (JOI19_jumps)C++17
0 / 100
35 ms4428 KiB
#include <bits/stdc++.h> #define debug(x) if(1) cout << #x << " is " << x << "\n"; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; int getans(int A[], int N){ vector<pair<int,int>> V; for(int i=0;i<N;i++) V.push_back({A[i],i}); sort(V.begin(), V.end(), greater<pair<int,int>>()); int lorg = 20; vector<int> V2; for(int i=0;i<min(lorg,N);i++){ V2.push_back(V[i].second); } vector<int> V3; for(int i=0;i<N;i++){ if(V[i].first == V[lorg-1].first) V3.push_back(i); } int ans = 0; if((int)V3.size() > lorg && lorg <= N) ans = V[lorg-1].first * 3; else{ for(auto i:V3){ if(i>=lorg) V2.push_back(i); } } int sufmax[N]; //cout << N << "\n"; //cout << A[N-1] << '\n'; sufmax[N-1] = A[N-1]; for(int i=N-2;i>=0;i--){ sufmax[i] = max(sufmax[i+1], A[i]); } //for(int i=0;i<N;i++) cout << sufmax[i] << " "; for(auto i:V2){ //debug(i); for(int j=0;j<i;j++){ int grr = 2 * i - j; if(grr >= N) continue; ans = max(ans, A[i] + A[j] + sufmax[grr]); //cout << i << " " << j << " " << grr << ' ' << sufmax[grr] << '\n'; } } return ans; } main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N; cin >> N; int A[N]; for(int i=0;i<N;i++) cin >> A[i]; int Q; cin >> Q; for(int i=0;i<Q;i++){ int l,r; cin >> l >> r; l--; r--; int x = r - l + 1; int B[x]; for(int i=0;i<x;i++){ B[i] = A[i+l]; } cout << getans(B, x) << '\n'; } }

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

jumps.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...