QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#137821 | #6343. Bitaro's travel | Rafi22# | 0 | 1ms | 3640kb | C++14 | 1.7kb | 2023-08-10 17:58:53 | 2024-07-04 01:31:04 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
//#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000000000000007;
int mod=1000000007;
int mod1=998244353;
const int N=200007;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<int>a(n+2);
a[0]=-inf;
for(int i=1;i<=n;i++) cin>>a[i];
a[n+1]=inf;
int q;
cin>>q;
while(q--)
{
int x,ans=0;
cin>>x;
int l=lower_bound(all(a),x)-a.begin();
bool side=0;
ans+=min(x-a[l],a[l+1]-x);
if(x-a[l]>a[l+1]-x) l++;
int r=l;
while(l>1||r<n)
{
if(side)
{
if(a[r+1]-a[r]<a[r]-a[l-1])
{
ans+=a[r+1]-a[r];
r++;
}
else
{
side=0;
ans+=a[r]-a[l-1];
l--;
}
}
else
{
if(a[l]-a[l-1]<=a[r+1]-a[l])
{
ans+=a[l]-a[l-1];
l--;
}
else
{
side=1;
ans+=a[r+1]-a[l];
r++;
}
}
}
// if(side) ans+=a[n]-a[r];
// else ans+=a[l]-a[1];
cout<<ans<<endl;
}
return 0;
}
/*
5
0 5 6 7 9
1
7
*/
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3640kb
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:
809906500
result:
wrong answer 1st numbers differ - expected: '809906250', found: '809906500'
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:
200089 -1999999999074805259 -2000000000074603096 346046 -2000000000074425795 269768 313076 -2000000000074423881 366120 -2000000000074539456 -2000000000074441433 348433 -2000000000074462958 -2000000000074544637 -2000000000074502663 332141 311760 -2000000000074523461 -2000000000074459481 366459 -20000...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%