Submission #527778

# Submission time Handle Problem Language Result Execution time Memory
527778 2022-02-18T09:20:07 Z boris_mihov Diamond Hands (innopolis2021_final_B) C++14
24 / 100
45 ms 5388 KB
#include <iostream>
#include <vector>
const int maxn = 2e5+10;

int n;
std::pair < int, int > d[maxn];
std::vector < std::pair < int, char > > ans;

void invalid() {

    std::cout << -1 << '\n';
    exit(0);

}

void solve() {

    for (int i = 1 ; i <= n ; ++i) {

        int diff = d[i].first - d[i-1].first;
        int desired = d[i].second - d[i-1].second;
        if (!(-diff <= desired && desired <= diff && (diff - desired) % 2 == 0)) invalid();

        if (desired == diff) {

            if (i == 2 && ans.size() == 2) swap(ans.front(), ans.back());
            if (!ans.empty() && ans.back().second == '+') ans.back().first += diff;
            else ans.push_back({diff, '+'});
            continue;

        }

        if (desired == -diff) {

            if (!ans.empty() && ans.back().second == '-') ans.back().first += diff;
            else ans.push_back({diff, '-'}); 
            continue;          

        }

        int subtract = (diff - desired) / 2;
        int add = diff - subtract;

        if (i == 1) {

            ans.push_back({add, '+'});
            ans.push_back({subtract, '-'});
            continue;

        }

        if (ans.back().second == '+') {

            ans.back().first += add;
            ans.push_back({subtract, '-'});
            continue;

        }

        ans.back().first += subtract;
        ans.push_back({add, '+'});

    }

    std::cout << ans.size() << '\n';
    for (int i = 0 ; i < ans.size() ; ++i)
        std::cout << ans[i].first << ' ' << ans[i].second << '\n';

}

void read() {

    std::cin >> n;
    for (int i = 1 ; i <= n ; ++i)
        std::cin >> d[i].first >> d[i].second;

}

void fast_io() {

    std::ios_base :: sync_with_stdio(0);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

}

int t;
int main () {

    fast_io();
    read();
    solve();

    return 0;

}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:66:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int i = 0 ; i < ans.size() ; ++i)
      |                      ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 0 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 332 KB OK, n=2000 ans=1
9 Correct 1 ms 332 KB OK, n=2000 ans=1
10 Correct 1 ms 332 KB OK, n=2000 ans=1
11 Correct 1 ms 332 KB OK, n=2000 ans=1
12 Correct 0 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 0 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 332 KB OK, no solution, n=2000
21 Correct 1 ms 332 KB OK, no solution, n=2000
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 0 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 332 KB OK, n=2000 ans=1
9 Correct 1 ms 332 KB OK, n=2000 ans=1
10 Correct 1 ms 332 KB OK, n=2000 ans=1
11 Correct 1 ms 332 KB OK, n=2000 ans=1
12 Correct 0 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 0 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 332 KB OK, no solution, n=2000
21 Correct 1 ms 332 KB OK, no solution, n=2000
22 Correct 0 ms 204 KB OK, n=2 ans=2
23 Correct 1 ms 204 KB OK, n=3 ans=2
24 Correct 0 ms 204 KB OK, n=4 ans=1
25 Correct 0 ms 204 KB OK, n=5 ans=2
26 Correct 1 ms 204 KB OK, n=8 ans=2
27 Correct 0 ms 204 KB OK, n=88 ans=2
28 Correct 1 ms 204 KB OK, n=888 ans=2
29 Correct 1 ms 332 KB OK, n=2000 ans=2
30 Correct 1 ms 332 KB OK, n=2000 ans=2
31 Correct 1 ms 332 KB OK, n=2000 ans=2
32 Correct 1 ms 332 KB OK, n=2000 ans=2
33 Correct 0 ms 204 KB OK, n=2 ans=1
34 Correct 1 ms 204 KB OK, n=34 ans=2
35 Correct 1 ms 204 KB OK, n=567 ans=2
36 Correct 1 ms 204 KB OK, n=1234 ans=2
37 Correct 0 ms 204 KB OK, no solution, n=6
38 Correct 0 ms 204 KB OK, no solution, n=10
39 Correct 0 ms 204 KB OK, no solution, n=50
40 Correct 0 ms 204 KB OK, no solution, n=333
41 Correct 1 ms 332 KB OK, no solution, n=2000
42 Correct 1 ms 332 KB OK, no solution, n=2000
43 Correct 0 ms 204 KB OK, n=1 ans=2
44 Correct 0 ms 204 KB OK, n=1 ans=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 0 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 332 KB OK, n=2000 ans=1
9 Correct 1 ms 332 KB OK, n=2000 ans=1
10 Correct 1 ms 332 KB OK, n=2000 ans=1
11 Correct 1 ms 332 KB OK, n=2000 ans=1
12 Correct 0 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 0 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 332 KB OK, no solution, n=2000
21 Correct 1 ms 332 KB OK, no solution, n=2000
22 Correct 0 ms 204 KB OK, n=4 ans=2
23 Correct 1 ms 204 KB OK, n=6 ans=2
24 Correct 1 ms 204 KB OK, n=15 ans=2
25 Correct 0 ms 204 KB OK, n=200 ans=2
26 Correct 1 ms 204 KB OK, n=1000 ans=2
27 Correct 2 ms 332 KB OK, n=10000 ans=2
28 Correct 16 ms 972 KB OK, n=100000 ans=2
29 Correct 25 ms 1504 KB OK, n=159807 ans=2
30 Correct 31 ms 4552 KB OK, n=200000 ans=2
31 Correct 36 ms 4972 KB OK, n=200000 ans=2
32 Correct 45 ms 5356 KB OK, n=200000 ans=2
33 Correct 1 ms 208 KB OK, n=3 ans=2
34 Correct 0 ms 208 KB OK, n=45 ans=2
35 Correct 0 ms 336 KB OK, n=789 ans=2
36 Correct 1 ms 332 KB OK, n=2345 ans=2
37 Correct 12 ms 1992 KB OK, n=67890 ans=2
38 Correct 25 ms 3656 KB OK, no solution, n=159807
39 Correct 30 ms 4504 KB OK, no solution, n=200000
40 Correct 32 ms 4904 KB OK, no solution, n=200000
41 Correct 39 ms 5388 KB OK, no solution, n=200000
# Verdict Execution time Memory 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 0 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 0 ms 204 KB OK, n=200 ans=46
7 Correct 0 ms 204 KB OK, n=100 ans=5
8 Correct 0 ms 204 KB OK, n=200 ans=20
9 Correct 0 ms 204 KB OK, n=400 ans=76
10 Correct 1 ms 332 KB OK, n=1000 ans=196
11 Correct 1 ms 336 KB OK, n=1000 ans=434
12 Correct 1 ms 340 KB OK, n=1000 ans=582
13 Correct 1 ms 340 KB OK, n=1000 ans=798
14 Incorrect 1 ms 336 KB WA, participant didn't the optimal solution n=1000 ans=867 part=868
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 0 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 332 KB OK, n=2000 ans=1
9 Correct 1 ms 332 KB OK, n=2000 ans=1
10 Correct 1 ms 332 KB OK, n=2000 ans=1
11 Correct 1 ms 332 KB OK, n=2000 ans=1
12 Correct 0 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 0 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 332 KB OK, no solution, n=2000
21 Correct 1 ms 332 KB OK, no solution, n=2000
22 Correct 0 ms 204 KB OK, n=2 ans=2
23 Correct 1 ms 204 KB OK, n=3 ans=2
24 Correct 0 ms 204 KB OK, n=4 ans=1
25 Correct 0 ms 204 KB OK, n=5 ans=2
26 Correct 1 ms 204 KB OK, n=8 ans=2
27 Correct 0 ms 204 KB OK, n=88 ans=2
28 Correct 1 ms 204 KB OK, n=888 ans=2
29 Correct 1 ms 332 KB OK, n=2000 ans=2
30 Correct 1 ms 332 KB OK, n=2000 ans=2
31 Correct 1 ms 332 KB OK, n=2000 ans=2
32 Correct 1 ms 332 KB OK, n=2000 ans=2
33 Correct 0 ms 204 KB OK, n=2 ans=1
34 Correct 1 ms 204 KB OK, n=34 ans=2
35 Correct 1 ms 204 KB OK, n=567 ans=2
36 Correct 1 ms 204 KB OK, n=1234 ans=2
37 Correct 0 ms 204 KB OK, no solution, n=6
38 Correct 0 ms 204 KB OK, no solution, n=10
39 Correct 0 ms 204 KB OK, no solution, n=50
40 Correct 0 ms 204 KB OK, no solution, n=333
41 Correct 1 ms 332 KB OK, no solution, n=2000
42 Correct 1 ms 332 KB OK, no solution, n=2000
43 Correct 0 ms 204 KB OK, n=1 ans=2
44 Correct 0 ms 204 KB OK, n=1 ans=2
45 Correct 0 ms 204 KB OK, n=5 ans=3
46 Correct 1 ms 204 KB OK, n=10 ans=4
47 Correct 0 ms 204 KB OK, n=20 ans=5
48 Correct 0 ms 204 KB OK, n=50 ans=9
49 Correct 0 ms 204 KB OK, n=100 ans=18
50 Correct 0 ms 204 KB OK, n=200 ans=46
51 Correct 0 ms 204 KB OK, n=100 ans=5
52 Correct 0 ms 204 KB OK, n=200 ans=20
53 Correct 0 ms 204 KB OK, n=400 ans=76
54 Correct 1 ms 332 KB OK, n=1000 ans=196
55 Correct 1 ms 336 KB OK, n=1000 ans=434
56 Correct 1 ms 340 KB OK, n=1000 ans=582
57 Correct 1 ms 340 KB OK, n=1000 ans=798
58 Incorrect 1 ms 336 KB WA, participant didn't the optimal solution n=1000 ans=867 part=868
59 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Correct 0 ms 204 KB OK, n=3 ans=1
3 Correct 0 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 332 KB OK, n=2000 ans=1
9 Correct 1 ms 332 KB OK, n=2000 ans=1
10 Correct 1 ms 332 KB OK, n=2000 ans=1
11 Correct 1 ms 332 KB OK, n=2000 ans=1
12 Correct 0 ms 204 KB OK, n=2 ans=1
13 Correct 1 ms 204 KB OK, n=34 ans=1
14 Correct 0 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 332 KB OK, no solution, n=2000
21 Correct 1 ms 332 KB OK, no solution, n=2000
22 Correct 0 ms 204 KB OK, n=2 ans=2
23 Correct 1 ms 204 KB OK, n=3 ans=2
24 Correct 0 ms 204 KB OK, n=4 ans=1
25 Correct 0 ms 204 KB OK, n=5 ans=2
26 Correct 1 ms 204 KB OK, n=8 ans=2
27 Correct 0 ms 204 KB OK, n=88 ans=2
28 Correct 1 ms 204 KB OK, n=888 ans=2
29 Correct 1 ms 332 KB OK, n=2000 ans=2
30 Correct 1 ms 332 KB OK, n=2000 ans=2
31 Correct 1 ms 332 KB OK, n=2000 ans=2
32 Correct 1 ms 332 KB OK, n=2000 ans=2
33 Correct 0 ms 204 KB OK, n=2 ans=1
34 Correct 1 ms 204 KB OK, n=34 ans=2
35 Correct 1 ms 204 KB OK, n=567 ans=2
36 Correct 1 ms 204 KB OK, n=1234 ans=2
37 Correct 0 ms 204 KB OK, no solution, n=6
38 Correct 0 ms 204 KB OK, no solution, n=10
39 Correct 0 ms 204 KB OK, no solution, n=50
40 Correct 0 ms 204 KB OK, no solution, n=333
41 Correct 1 ms 332 KB OK, no solution, n=2000
42 Correct 1 ms 332 KB OK, no solution, n=2000
43 Correct 0 ms 204 KB OK, n=1 ans=2
44 Correct 0 ms 204 KB OK, n=1 ans=2
45 Correct 0 ms 204 KB OK, n=4 ans=2
46 Correct 1 ms 204 KB OK, n=6 ans=2
47 Correct 1 ms 204 KB OK, n=15 ans=2
48 Correct 0 ms 204 KB OK, n=200 ans=2
49 Correct 1 ms 204 KB OK, n=1000 ans=2
50 Correct 2 ms 332 KB OK, n=10000 ans=2
51 Correct 16 ms 972 KB OK, n=100000 ans=2
52 Correct 25 ms 1504 KB OK, n=159807 ans=2
53 Correct 31 ms 4552 KB OK, n=200000 ans=2
54 Correct 36 ms 4972 KB OK, n=200000 ans=2
55 Correct 45 ms 5356 KB OK, n=200000 ans=2
56 Correct 1 ms 208 KB OK, n=3 ans=2
57 Correct 0 ms 208 KB OK, n=45 ans=2
58 Correct 0 ms 336 KB OK, n=789 ans=2
59 Correct 1 ms 332 KB OK, n=2345 ans=2
60 Correct 12 ms 1992 KB OK, n=67890 ans=2
61 Correct 25 ms 3656 KB OK, no solution, n=159807
62 Correct 30 ms 4504 KB OK, no solution, n=200000
63 Correct 32 ms 4904 KB OK, no solution, n=200000
64 Correct 39 ms 5388 KB OK, no solution, n=200000
65 Correct 0 ms 204 KB OK, n=5 ans=3
66 Correct 1 ms 204 KB OK, n=10 ans=4
67 Correct 0 ms 204 KB OK, n=20 ans=5
68 Correct 0 ms 204 KB OK, n=50 ans=9
69 Correct 0 ms 204 KB OK, n=100 ans=18
70 Correct 0 ms 204 KB OK, n=200 ans=46
71 Correct 0 ms 204 KB OK, n=100 ans=5
72 Correct 0 ms 204 KB OK, n=200 ans=20
73 Correct 0 ms 204 KB OK, n=400 ans=76
74 Correct 1 ms 332 KB OK, n=1000 ans=196
75 Correct 1 ms 336 KB OK, n=1000 ans=434
76 Correct 1 ms 340 KB OK, n=1000 ans=582
77 Correct 1 ms 340 KB OK, n=1000 ans=798
78 Incorrect 1 ms 336 KB WA, participant didn't the optimal solution n=1000 ans=867 part=868
79 Halted 0 ms 0 KB -