답안 #791613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791613 2023-07-24T08:04:11 Z n3rm1n Snowball (JOI21_ho_t2) C++17
33 / 100
3 ms 724 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const long long MAXN = 2005;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
long long n, q;
long long a[MAXN], wind[MAXN];
long long moveleft[MAXN], moveright[MAXN];

void read()
{
    cin >> n >> q;
    for (long long i = 1; i <= n; ++ i)
        cin >> a[i];
    long long pos = 0;
    for (long long i = 1; i <= q; ++ i)
    {
        cin >> wind[i];
        pos += wind[i];
        moveleft[i] = min(pos, moveleft[i-1]);
        moveright[i] = max(pos, moveright[i-1]);
    }

    for (long long i = 1; i <= q; ++ i)
    {
        moveleft[i] *= -1;
       // cout << moveleft[i] << " " << moveright[i] << endl;
    }
}
long long ans[MAXN];
void solve()
{
    for (long long i = 2; i <= n; ++ i)
    {
        int f = 0;
        for (long long j = 1; j <= q; ++ j)
        {
            if(a[i-1] + moveright[j] >= a[i] - moveleft[j])
            {
               // cout << "***" << endl;
               // cout << i-1 << " " << i << " " << j << endl;
                long long segment = a[i] - a[i-1];
                long long to_first = 0, to_second = 0;
                if(wind[j] >= 0)
                {
                    to_second = moveleft[j];
                    to_first = segment - to_second;
                }
                else
                {
                    to_first = moveright[j];
                    to_second = segment - to_first;
                }
                //cout << to_first << " " << to_second << endl;
                ans[i-1] += to_first;
                ans[i] += to_second;
                f = 1;
                break;
            }
        }
         if(f == 0)
         {
             ans[i-1] += moveright[q];
             ans[i] += moveleft[q];
         }


    }
    ans[1] += moveleft[q];
    ans[n] += moveright[q];
    for (long long i = 1; i <= n; ++ i)
        cout << ans[i] << " ";
    cout << endl;
}
int main()
{
    speed();

    read();
    solve();
    return 0;
}
/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Runtime error 1 ms 724 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -