답안 #417869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417869 2021-06-04T12:44:02 Z 최서현(#7474) Diamond Hands (innopolis2021_final_B) C++17
0 / 100
2 ms 332 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    pii A[n];
    int a = 0, b = 0;
    for(int i = 0; i < n; ++i)
    {
        int x, y; cin >> x >> y;
        if((x ^ y) & 1) { cout << -1; return 0; }
        if(x + y < 0 || x < y) { cout << -1; return 0; }
        int z = x + y >> 1;
        A[i] = {x - a, z - b};
        a = x; b = z;
    }

    bool flag = true;
    for(int i = 0; i < n; ++i)
    {
        if(A[i].ss == 0) { flag = (i % 2 == 0); break; }
        if(A[i].ff == A[i].ss) { flag = (i % 2 == 1); break; }
    }

    vector<pair<int, bool>> ans;

    int pr = 0;
    for(int i = 0; i < n; ++i)
    {
        if(flag)
        {
            pr += A[i].ff - A[i].ss;
            if(A[i].ss != 0)
            {
                ans.push_back({pr, flag});
                pr = A[i].ss;
                flag = false;
            }
        }
        else
        {
            pr += A[i].ss;
            if(A[i].ff != A[i].ss)
            {
                ans.push_back({pr, flag});
                pr = A[i].ff - A[i].ss;
                flag = true;
            }
        }
    }

    if(pr) ans.push_back({pr, flag});

    cout << ans.size() << '\n';
    for(auto i : ans) cout << i.ff << (i.ss ? " -\n" : " +\n");
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:33:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |         int z = x + y >> 1;
      |                 ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 1 ms 204 KB OK, n=1 ans=1
4 Correct 1 ms 204 KB OK, n=5 ans=1
5 Correct 1 ms 204 KB OK, n=8 ans=1
6 Correct 0 ms 204 KB OK, n=88 ans=1
7 Correct 1 ms 204 KB OK, n=888 ans=1
8 Correct 1 ms 204 KB OK, n=2000 ans=1
9 Correct 1 ms 204 KB OK, n=2000 ans=1
10 Correct 1 ms 204 KB OK, n=2000 ans=1
11 Correct 2 ms 204 KB OK, n=2000 ans=1
12 Correct 1 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 1 ms 204 KB OK, n=567 ans=1
15 Correct 1 ms 204 KB OK, n=1234 ans=1
16 Correct 0 ms 204 KB OK, no solution, n=2
17 Correct 0 ms 204 KB OK, no solution, n=3
18 Correct 0 ms 204 KB OK, no solution, n=40
19 Correct 0 ms 204 KB OK, no solution, n=118
20 Correct 1 ms 204 KB OK, no solution, n=2000
21 Incorrect 1 ms 204 KB Integer 0 violates the range [1, 10^8]
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 1 ms 204 KB OK, n=1 ans=1
4 Correct 1 ms 204 KB OK, n=5 ans=1
5 Correct 1 ms 204 KB OK, n=8 ans=1
6 Correct 0 ms 204 KB OK, n=88 ans=1
7 Correct 1 ms 204 KB OK, n=888 ans=1
8 Correct 1 ms 204 KB OK, n=2000 ans=1
9 Correct 1 ms 204 KB OK, n=2000 ans=1
10 Correct 1 ms 204 KB OK, n=2000 ans=1
11 Correct 2 ms 204 KB OK, n=2000 ans=1
12 Correct 1 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 1 ms 204 KB OK, n=567 ans=1
15 Correct 1 ms 204 KB OK, n=1234 ans=1
16 Correct 0 ms 204 KB OK, no solution, n=2
17 Correct 0 ms 204 KB OK, no solution, n=3
18 Correct 0 ms 204 KB OK, no solution, n=40
19 Correct 0 ms 204 KB OK, no solution, n=118
20 Correct 1 ms 204 KB OK, no solution, n=2000
21 Incorrect 1 ms 204 KB Integer 0 violates the range [1, 10^8]
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 1 ms 204 KB OK, n=1 ans=1
4 Correct 1 ms 204 KB OK, n=5 ans=1
5 Correct 1 ms 204 KB OK, n=8 ans=1
6 Correct 0 ms 204 KB OK, n=88 ans=1
7 Correct 1 ms 204 KB OK, n=888 ans=1
8 Correct 1 ms 204 KB OK, n=2000 ans=1
9 Correct 1 ms 204 KB OK, n=2000 ans=1
10 Correct 1 ms 204 KB OK, n=2000 ans=1
11 Correct 2 ms 204 KB OK, n=2000 ans=1
12 Correct 1 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 1 ms 204 KB OK, n=567 ans=1
15 Correct 1 ms 204 KB OK, n=1234 ans=1
16 Correct 0 ms 204 KB OK, no solution, n=2
17 Correct 0 ms 204 KB OK, no solution, n=3
18 Correct 0 ms 204 KB OK, no solution, n=40
19 Correct 0 ms 204 KB OK, no solution, n=118
20 Correct 1 ms 204 KB OK, no solution, n=2000
21 Incorrect 1 ms 204 KB Integer 0 violates the range [1, 10^8]
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB OK, n=5 ans=3
2 Correct 1 ms 204 KB OK, n=10 ans=4
3 Correct 1 ms 204 KB OK, n=20 ans=5
4 Correct 0 ms 204 KB OK, n=50 ans=9
5 Correct 0 ms 204 KB OK, n=100 ans=18
6 Correct 1 ms 204 KB OK, n=200 ans=46
7 Correct 1 ms 204 KB OK, n=100 ans=5
8 Correct 0 ms 204 KB OK, n=200 ans=20
9 Correct 1 ms 204 KB OK, n=400 ans=76
10 Correct 1 ms 204 KB OK, n=1000 ans=196
11 Correct 1 ms 332 KB OK, n=1000 ans=434
12 Correct 1 ms 332 KB OK, n=1000 ans=582
13 Correct 1 ms 332 KB OK, n=1000 ans=798
14 Correct 1 ms 332 KB OK, n=1000 ans=867
15 Correct 1 ms 204 KB OK, n=2000 ans=200
16 Correct 1 ms 332 KB OK, n=1998 ans=500
17 Correct 1 ms 332 KB OK, n=2000 ans=800
18 Correct 1 ms 332 KB OK, n=1995 ans=1000
19 Correct 2 ms 332 KB OK, n=2000 ans=1500
20 Correct 1 ms 332 KB OK, n=2000 ans=2000
21 Correct 0 ms 204 KB OK, no solution, n=10
22 Correct 1 ms 204 KB OK, no solution, n=50
23 Incorrect 1 ms 204 KB Integer 0 violates the range [1, 10^8]
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 1 ms 204 KB OK, n=1 ans=1
4 Correct 1 ms 204 KB OK, n=5 ans=1
5 Correct 1 ms 204 KB OK, n=8 ans=1
6 Correct 0 ms 204 KB OK, n=88 ans=1
7 Correct 1 ms 204 KB OK, n=888 ans=1
8 Correct 1 ms 204 KB OK, n=2000 ans=1
9 Correct 1 ms 204 KB OK, n=2000 ans=1
10 Correct 1 ms 204 KB OK, n=2000 ans=1
11 Correct 2 ms 204 KB OK, n=2000 ans=1
12 Correct 1 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 1 ms 204 KB OK, n=567 ans=1
15 Correct 1 ms 204 KB OK, n=1234 ans=1
16 Correct 0 ms 204 KB OK, no solution, n=2
17 Correct 0 ms 204 KB OK, no solution, n=3
18 Correct 0 ms 204 KB OK, no solution, n=40
19 Correct 0 ms 204 KB OK, no solution, n=118
20 Correct 1 ms 204 KB OK, no solution, n=2000
21 Incorrect 1 ms 204 KB Integer 0 violates the range [1, 10^8]
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 1 ms 204 KB OK, n=1 ans=1
4 Correct 1 ms 204 KB OK, n=5 ans=1
5 Correct 1 ms 204 KB OK, n=8 ans=1
6 Correct 0 ms 204 KB OK, n=88 ans=1
7 Correct 1 ms 204 KB OK, n=888 ans=1
8 Correct 1 ms 204 KB OK, n=2000 ans=1
9 Correct 1 ms 204 KB OK, n=2000 ans=1
10 Correct 1 ms 204 KB OK, n=2000 ans=1
11 Correct 2 ms 204 KB OK, n=2000 ans=1
12 Correct 1 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 1 ms 204 KB OK, n=567 ans=1
15 Correct 1 ms 204 KB OK, n=1234 ans=1
16 Correct 0 ms 204 KB OK, no solution, n=2
17 Correct 0 ms 204 KB OK, no solution, n=3
18 Correct 0 ms 204 KB OK, no solution, n=40
19 Correct 0 ms 204 KB OK, no solution, n=118
20 Correct 1 ms 204 KB OK, no solution, n=2000
21 Incorrect 1 ms 204 KB Integer 0 violates the range [1, 10^8]