QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#697864#5435. Clamped SequenceabsabsWA 0ms3692kbC++232.9kb2024-11-01 16:09:212024-11-01 16:09:21

Judging History

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

  • [2024-11-01 16:09:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3692kb
  • [2024-11-01 16:09:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ull unsigned long long
#define ms(x, y) memset(x, y, sizeof x);
#define debug(x) cout << #x << " = " << x << endl;
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define fre                           \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const double esp = 1e-6;
const ull MOD1 = 1610612741;
const ull MOD2 = 805306457;
const ull BASE1 = 1331;
const ull BASE2 = 131;
#define pre(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
char *p1, *p2, buf[100000]; // 快读和同步流二者只能选一个
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
int read()
{
	int x = 0, f = 1;
	char ch = nc();
	while (ch < 48 || ch > 57)
	{
		if (ch == '-')
			f = -1;
		ch = nc();
	}
	while (ch >= 48 && ch <= 57)
		x = x * 10 + ch - 48, ch = nc();
	return x * f;
}
void write(int x)
{
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}
int n,d,a[N];

void solve()
{
	cin >> n >> d ;
    pre(i,1,n) cin >> a[i];
    int ans = 0;
    pre(i,1,n)
    {
        int l=a[i];
        int r = a[i] + d,tp = 0;
        pre(j,2,n)
        {
            int tp1 = 0,tp2 = 0;
            if(a[j - 1] < l) tp1 = l;
            else if(a[j - 1] > r) tp1 = r;
            else tp1 = a[j - 1];
            if(a[j] < l) tp2 = l;
            else if(a[j] > r) tp2 = r;
            else tp2 = a[j];
            tp += abs(tp1 - tp2);
            // cout < tp1 << " " << tp2 <<
        }
        // cout << tp << " " << a[l] << " " << r << " " << ans << endl;
        ans = max(ans,tp);
        r=a[i];
        l=r-d;
        pre(j,2,n)
        {
            int tp1 = 0,tp2 = 0;
            if(a[j - 1] < l) tp1 = l;
            else if(a[j - 1] > r) tp1 = r;
            else tp1 = a[j - 1];
            if(a[j] < l) tp2 = l;
            else if(a[j] > r) tp2 = r;
            else tp2 = a[j];
            tp += abs(tp1 - tp2);
            // cout < tp1 << " " << tp2 <<
        }
        // cout << tp << " " << a[l] << " " << r << " " << ans << endl;
        ans = max(ans,tp);
    }
    cout << ans << endl;
}
// #define LOCAL
signed main()
{
	ios
	// fre
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	auto start = std::chrono::high_resolution_clock::now();
#endif
	
	int t = 1;
	// cin >> t;
	while (t--)
		solve();
	
#ifdef LOCAL
	auto end = std::chrono::high_resolution_clock::now();
	cout << "Execution time: "
	<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
	<< " ms" << '\n';
#endif
	return 0;
}


详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3692kb

input:

8 3
3 1 4 1 5 9 2 6

output:

23

result:

wrong answer 1st numbers differ - expected: '15', found: '23'