QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137729 | #6343. Bitaro's travel | Asymmetry# | 0 | 1ms | 3564kb | C++20 | 2.4kb | 2023-08-10 17:08:53 | 2024-07-04 01:30:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
#ifdef DEBUG
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<int> t(n);
REP (i, n)
cin >> t[i];
auto find_start = [&](int x) {
int ind = int(upper_bound(t.begin(), t.end(), x) - t.begin());
int ret = 0;
if (ind < n && abs(t[ret] - x) > abs(t[ind] - x))
ret = ind;
if (ind && abs(t[ret] - x) >= abs(t[ind - 1] - x))
ret = ind - 1;
return ret;
};
const int INF = int(1e9);
auto dist = [&](int p, int q) {
if (p < 0 || q < 0 || p >= n || q >= n)
return INF;
return abs(t[p] - t[q]);
};
debug(t);
vector<int> start_lf(n, -2), start_rg(n, n + 1);
FOR (i, 1, n - 1)
FOR (j, i, n - 1)
if (t[j] - t[i] >= t[i] - t[i - 1]) {
start_lf[i] = j;
break;
}
debug(start_lf);
REP (i, n - 1)
for (int j = i; j >= 0; --j)
if (t[i] - t[j] > t[i + 1] - t[i]) {
start_rg[i] = j;
break;
}
debug(start_rg);
// return 0;
int q;
cin >> q;
REP (xd, q) {
int x;
cin >> x;
int cur = find_start(x);
LL ans = abs(t[cur] - x);
int lf = cur, rg = cur;
int side = dist(cur - 1, cur) <= dist(cur, cur + 1);
int cnt = 0;
while (lf || rg < n - 1) {
++cnt;
assert(cnt < 100);
debug(lf, rg, side);
if (side) {
// idziemy w lewo
int poz = 0;
REP (i, lf)
if (start_lf[i] > rg + 1)
poz = i;
debug(poz);
ans += dist(lf, poz);
lf = poz;
if (rg < n - 1) {
ans += dist(lf, rg + 1);
++rg;
side ^= 1;
}
}
else {
// idziemy w prawo
int poz = n - 1;
FOR (i, rg, n - 1)
if (start_rg[i] < lf - 1) {
poz = i;
break;
}
debug(poz);
ans += dist(rg, poz);
rg = poz;
if (lf) {
ans += dist(rg, lf - 1);
--lf;
side ^= 1;
}
}
}
cout << ans << '\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: 3564kb
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: -5
Wrong Answer
time: 1ms
memory: 3548kb
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:
1035633552
result:
wrong answer 1st numbers differ - expected: '722242888', found: '1035633552'
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 346046 379455 269768 313076 381369 366120 265794 363817 348433 342292 260613 302587 332141 311760 281789 345769 366459 218270 221124 225466 313243 322095 332977 281351 224651 257342 259560 206246 231269 316285 371811 394056 382486 202443 357928 359464 357158 354417 368006 326...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%