QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#177032#5435. Clamped Sequenceucup-team963#Compile Error//C++14723b2023-09-12 14:34:532023-09-12 14:34:53

Judging History

你现在查看的是最新测评结果

  • [2023-09-12 14:34:53]
  • 评测
  • [2023-09-12 14:34:53]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;

typedef long long ll;

ll calc(vector<int> x, int l, int r) {
    int n = x.size();
    for(int i = 0; i < n; ++ i) {
        x[i] = max(x[i], l);
        x[i] = min(x[i], r);
    }
    ll ret = 0;
    rep(i,1,n - 1) ret += abs(a[i] - a[i - 1]);
    return ret;
}

int main() {
    if(fopen("yl.in", "r")) {
        freopen("yl.in", "r", stdin);
        freopen("yl.out", "w", stdout);
    }

    int n, d;
    cin >> n >> d;
    vector<int> a(n);
    rep(i,0,n - 1) cin >> a[i];
    ll ans = 0x3f3f3f3f3f3f3f3fl;
    rep(i,0,n - 1) calc(x, a[i], a[i] + d);
    cout << ans << endl;
    return 0;
}

詳細信息

answer.code: In function ‘ll calc(std::vector<int>, int, int)’:
answer.code:14:31: error: ‘a’ was not declared in this scope
   14 |     rep(i,1,n - 1) ret += abs(a[i] - a[i - 1]);
      |                               ^
answer.code: In function ‘int main()’:
answer.code:29:25: error: ‘x’ was not declared in this scope
   29 |     rep(i,0,n - 1) calc(x, a[i], a[i] + d);
      |                         ^
answer.code:20:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         freopen("yl.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
answer.code:21:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         freopen("yl.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~