이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int INF = 1LL<<62;
int maxbloat = 1008;
signed main() {
int local = 0;
if (local) {
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
}
/*#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif*/ //fast IO
int n,l; cin >> n >> l;
vector<int> balls;
for (int i=0; i<n; i++) {
int x; cin >> x; balls.push_back(x);
}
vector<int> coords;
map<int,int> revcoords;
for (int i=0; i<n; i++) {
coords.push_back(balls[i]);
}
sort(coords.begin(), coords.end());
coords.erase(unique(coords.begin(), coords.end()), coords.end());
int q; cin >> q;
if (coords.size()>maxbloat) {
while (q--) {
int s,g,t; cin >> s >> g >> t; cout << "No" << endl;
}
return 0;
}
for (int i=0; i<coords.size(); i++) {
revcoords[coords[i]] = i;
}
//dp[l][r-l][x-l] = min cost of picking up balls l through r, if we start at pos of ball x (l<=x<=r)
n = coords.size();
vector<int> counts(n,0);
vector<int> pref(n+1,0);
for (int i=0; i<balls.size(); i++) {
counts[revcoords[balls[i]]]++;
}
for (int i=0; i<n; i++) {
pref[i+1] = pref[i] + counts[i];
}
int totballs = balls.size();
vector<int> start_ans0(n);
vector<int> start_ans1(n);
for (int x=0; x<n; x++) {
vector<vector<int>> dp0(n); //finish at left
vector<vector<int>> dp1(n); //finish at right
for (int l=0; l<=x; l++) {
dp0[l]=dp1[l]=vector<int>(n-x,INF); //dp[l][x] to dp[l][n-1]
}
dp0[x][0] = dp1[x][0] = 0;
for (int rml=1; rml<n; rml++) {
for (int l=max((int)0,x-rml); l<=min(n-rml-1,x); l++) {
int r = l+rml;
//cout << l <<" " << r <<" " << x << " " << r-l <<" " << r-1-l << " " << coords.size() << endl;
//length is r-l+1
int cta = counts[l];
int ctb = pref[r]-pref[l+1];
int ctc = counts[r];
int rem1 = totballs-ctb-ctc+1;
int rem2 = totballs-ctb-cta+1;
//cout << cta <<" " << ctb <<" " << ctc <<" " << rem1 <<" " << rem2 << endl;
if (l!=x) {
//cout << l+1 <<" " << r-x <<" " << "d " << dp0[l+1][r-x] << endl;
dp0[l][r-x] = min(dp0[l+1][r-x]+(rem1)*(coords[l+1]-coords[l]),dp1[l+1][r-x]+(rem1)*(coords[r]-coords[l]));
}
if (r!=x) {
dp1[l][r-x] = min(dp1[l][r-1-x]+(rem2)*(coords[r]-coords[r-1]),dp0[l][r-1-x]+(rem2)*(coords[r]-coords[l]));
}
}
}
start_ans0[x] = dp0[0][n-1-x];
start_ans1[x] = dp1[0][n-1-x];
//cout << "calced " << x <<" " << start_ans0[x] <<" " << start_ans1[x] << endl;
}
//subtract n from time limit
while (q--) {
int s,g,t; cin >> s >> g >> t;
t-=totballs;
int succ = upper_bound(coords.begin(), coords.end(), g)-coords.begin();
int pred = succ-1;
//cout << "doing query " << s <<" " << g << " " << t << " " << pred <<" " << succ << endl;
int ans = INF;
if (pred>=0) {
ans=min(ans,min(start_ans0[pred]+(g-coords[pred])*(1+totballs)+abs(s-coords[0]),start_ans1[pred]+(g-coords[pred])*(1+totballs)+abs(s-coords[n-1])));
}
if (succ<=n-1) {
ans=min(ans,min(start_ans0[succ]+(coords[succ]-g)*(1+totballs)+abs(s-coords[0]),start_ans1[succ]+(coords[succ]-g)*(1+totballs)+abs(s-coords[n-1])));
}
if (ans<=t) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
//cout << ans << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:36:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
36 | if (coords.size()>maxbloat) {
| ~~~~~~~~~~~~~^~~~~~~~~
Main.cpp:43:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i=0; i<coords.size(); i++) {
| ~^~~~~~~~~~~~~~
Main.cpp:50:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i=0; i<balls.size(); i++) {
| ~^~~~~~~~~~~~~
Main.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |