QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#137735#6343. Bitaro's travelWonderfulWhale#0 1ms3744kbC++201.2kb2023-08-10 17:11:152024-07-04 01:30:24

Judging History

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

  • [2024-07-04 01:30:24]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3744kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 17:11:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int64_t int
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

vector<pii> G[200009];
int dis[200009];
int tab[200009];

void dfs(int x) {
	for(pii y:G[x]) {
		dis[y.st] = dis[x]+y.nd;
		dfs(y.st);
	}
}

int d(int x, int y) {
	return abs(tab[x]-tab[y]);
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	for(int i=0;i<n;i++) 
		cin >> tab[i];
	for(int i=1;i<n-1;i++) {
		if(d(i-1, i)<=d(i, i+1)) {
			int target = i-1;
			while(target-1>=0&&d(target-1, i)<=d(i,i+1)) target--;
			G[target].pb({i, d(target, i)});
			//cout << "edge: " << i << " -> " << target << "\n";
		} else {
			int target = i+1;
			while(target+1<n&&d(target+1, i)<=d(i,i-1)) target++;
			G[target].pb({i, d(target, i)});
			//cout << "edge: " << i << " -> " << target << "\n";
		}
	}
	dfs(0);
	dfs(n-1);

	int q;
	cin >> q;
	while(q--) {
		int x;
		cin >> x;
		pii start = {1e9, -1};
		for(int i=0;i<n;i++) {
			start = min(start, {abs(tab[i]-x), i});
		}
		//cout << start.st << " " << start.nd << "\n";
		cout << d(0, n-1)+start.st+dis[start.nd] << "\n";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3744kb

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:

809905983

result:

wrong answer 1st numbers differ - expected: '809906250', found: '809905983'

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:

200107
999999991
202154
200098
379455
200098
200098
381369
200098
265794
363817
200098
342292
260613
302587
200098
200098
281789
345769
200098
218270
200098
200098
200098
200098
332977
200098
224651
200098
259560
206246
231269
200098
371811
200098
382486
202443
200098
359464
200098
354417
200098
200...

result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%