QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137854#6343. Bitaro's travelRafi22#0 1ms3632kbC++142.0kb2023-08-10 18:23:462024-07-04 01:31:34

Judging History

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

  • [2024-07-04 01:31:34]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3632kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 18:23:46]
  • 提交

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();
        ans+=min(a[l]-x,x-a[l-1]);
        if(a[l]-x>=x-a[l-1]) l--;
        int r=l;
        bool side=0;
         while(l>1||r<n)
        {
            if(l==1)
            {
                if(side) ans+=a[n]-a[r];
                else ans+=a[n]-a[l];
                break;
            }
            if(r==n)
            {
                if(side) ans+=a[r]-a[1];
                else ans+=a[l]-a[1];
                break;
            }
            if(side)
            {
                for(int i=r+1;i<=n;i++)
                {
                    if(2*a[i]-a[i+1]<=a[l-1])
                    {
                        ans+=a[i]-a[r];
                        ans+=a[i]-a[l];
                        r=i;
                        break;
                    }
                }
            }
            else
            {
                for(int i=l-1;i>0;i--)
                {
                    if(2*a[i]-a[i-1]>a[r+1])
                    {
                        ans+=a[l]-a[i];
                        ans+=a[r]-a[i];
                        l=i;
                        break;
                    }
                }
            }
            side^=1;
        }
        cout<<ans<<endl;
    }


    return 0;
}
/*
5
0 5 6 7 9
1
7
*/


詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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: 3632kb

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:

722242988

result:

wrong answer 1st numbers differ - expected: '722242888', found: '722242988'

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%