Submission #375794

#TimeUsernameProblemLanguageResultExecution timeMemory
375794fhvirusTwo Antennas (JOI19_antennas)C++17
2 / 100
3 ms492 KiB
// Knapsack DP is harder than FFT. #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ff first #define ss second #define pb emplace_back #define FOR(i,n) for(int i = 0; i < (n); ++i) #define FOO(i,a,b) for(int i = (a); i <= (b); ++i) #define AI(x) begin(x),end(x) template<typename I> bool chmax(I &a, I b){ return a < b ? ( a = b, true ) : false;} template<typename I> bool chmin(I &a, I b){ return a > b ? ( a = b, true ) : false;} #ifdef OWO #define debug(args...) LKJ("[ " + string(#args) + " ]", args) void LKJ(){cerr<<endl;} template<class I, class...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);} template<class I> void DE(I a, I b){ while(a < b) cerr<<*a<<" \n"[next(a) == b], ++a;} #else #define debug(...) 0 #define DE(...) 0 #endif const int N = 333; int n, q; int h[N]; bool g[N][N]; int32_t main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; assert(n < N); FOR(i,n){ int l, r; cin >> h[i] >> l >> r; FOR(j,n){ int d = abs(i - j); if(l <= d and d <= r) g[i][j] = true; } } cin >> q; assert(q < N); FOR(_,q){ int l, r; cin >> l >> r; --l, --r; int ans = -1; FOO(i,l,r){ FOO(j,i+1,r){ if(g[i][j] and g[j][i]) chmax(ans, abs(h[i] - h[j])); } } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...