QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124020#6343. Bitaro's travelAdam_GS#0 1ms4084kbC++201.2kb2023-07-14 03:59:352024-07-04 00:38:46

Judging History

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

  • [2024-07-04 00:38:46]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:4084kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-14 03:59:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
ll T[LIM], n;
map<pair<int,int>,ll>mp;
ll solve(int a, int b) {
	if(mp.find({a, b})!=mp.end()) return mp[{a, b}];
	if(abs(a-b)==n-1) mp[{a, b}]=0;
	else if(a<=b) {
		if(a && (b==n-1 || T[b+1]-T[a]>=T[a]-T[a-1])) mp[{a, b}]=solve(a-1, b)+T[a]-T[a-1];
		else mp[{a, b}]=solve(b+1, a)+T[b+1]-T[a];
	} else {
		if(a<n-1 && (!b || T[a]-T[b-1]>T[a+1]-T[a])) mp[{a, b}]=solve(a+1, b)+T[a+1]-T[a];
		else mp[{a, b}]=solve(b-1, a)+T[a]-T[b-1];
	}
	return mp[{a, b}];
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	rep(i, n) cin >> T[i];
	int q;
	cin >> q;
	while(q--) {
		ll x;
		cin >> x;
		if(x<=T[0]) cout << solve(0, 0)+T[0]-x << '\n';
		else if(x>=T[n-1]) cout << solve(n-1, n-1)+x-T[n-1] << '\n';
		else {
			int po=0, ko=n-1;
			while(po<ko) {
				int sr=(po+ko)/2;
				if(T[sr]<x) po=sr+1; else ko=sr;
			}
			cout << min(solve(po, po)+T[po]-x, solve(po-1, po-1)+x-T[po-1]) << '\n';
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 1ms
memory: 4020kb

input:

2000
154914587 154914588 154914591 154914592 154914594 154914596 154914598 154914599 154914601 154914603 154914608 154914610 154914612 154914615 154914618 154914619 154914621 154914622 154914626 154914627 154914631 154914633 154914636 154914638 154914640 154914641 154914642 154914644 154914645 15491...

output:

809906250

result:

ok 1 number(s): "809906250"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3956kb

input:

2000
356563033 356563037 356563039 356563041 356563043 356563045 356563048 356563050 356563051 356563052 356563054 356563055 356563057 356563060 356563061 356563062 356563065 356563067 356563069 356563074 356563076 356563077 356563079 356563080 356563082 356563085 356563086 356563090 356563091 35656...

output:

722242888

result:

ok 1 number(s): "722242888"

Test #3:

score: 0
Accepted
time: 0ms
memory: 4008kb

input:

2000
24477976 24477978 24477981 24477982 24477986 24477988 24477990 24477992 24477993 24477996 24477998 24477999 24478001 24478002 24478003 24478005 24478007 24478008 24478009 24478011 24478012 24478013 24478015 24478016 24478017 24478019 24478020 24478022 24478024 24478026 24478029 24478031 2447803...

output:

795269579

result:

ok 1 number(s): "795269579"

Test #4:

score: -5
Wrong Answer
time: 1ms
memory: 4084kb

input:

2000
118383953 118383958 118383960 118383964 118383966 118383970 118383971 118383972 118383974 118383976 118383977 118383978 118383979 118383981 118383982 118383983 118383986 118383987 118383989 118383990 118383991 118383993 118383994 118383996 118383998 118383999 118384000 118384002 118384006 11838...

output:

633900955

result:

wrong answer 1st numbers differ - expected: '633902161', found: '633900955'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

200000
9 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%