이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
ll a,b,t, n, l;
ll arr[2005];
ll cache[2005][2005][2];
ll dp(ll x, ll y, ll pos){
if (cache[x][y][pos] != -1) return cache[x][y][pos];
if (x==y){
return cache[x][y][pos]= (n+1) * abs(arr[x]-b);
}
if (pos == 0){
ll idk = dp(x,y-1,1) + abs(arr[x]-arr[y])*(n-(y-x)) + abs(arr[y]-arr[y-1])*(n-(y-x)+1);
ll idk2 = dp(x+1,y,0) + abs(arr[x]-arr[x+1])*(n-(y-x)+1);
return cache[x][y][pos]=min(idk, idk2);
}
else if (pos == 1){
ll idk = dp(x+1,y,0) + abs(arr[y]-arr[x])*(n-(y-x)) + abs(arr[x] - arr[x+1])*(n-(y-x)+1);
ll idk2 = dp(x, y-1, 1) + abs(arr[y]-arr[y-1]) * (n-(y-x)+1);
return cache[x][y][pos]=min(idk, idk2);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> l;
FOR(i,0,n) cin >> arr[i];
sort(arr, arr+n);
ll q;
cin >> q;
FOR(i,0,q){
cin >> a >> b >> t;
FOR(i,0,2005) FOR(j,0,2005) FOR(k,0,2) cache[i][j][k]=-1;
ll ans = dp(0, n-1, 0) + abs(a-arr[0]);
ans = min(ans, dp(0, n-1, 1) + abs(a-arr[n-1]));
ans += n;
if (ans <= t) cout << "Yes" << "\n";
else cout << "No" << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'll dp(ll, ll, ll)':
Main.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
36 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |