답안 #417807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417807 2021-06-04T10:25:14 Z 반딧불(#7603) Diamond Hands (innopolis2021_final_B) C++17
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
int x[200002], y[200002];

vector<pair<int, char> > ans;

vector<pair<int, char> > solve(){
    vector<pair<int, char> > ans;
    ans.push_back(make_pair(0, '+'));
    for(int i=1; i<=n; i++){
        bool lastUp = ans.back().second == '+';
        int dir = 0;
        int xd = x[i] - x[i-1], yd = y[i] - y[i-1];
        if(xd == yd) dir = 1;
        if(xd == -yd) dir = 2;

        if(lastUp && dir == 1) ans.back().first += x[i] - x[i-1];
        else if(lastUp){
            int up = x[i] - (xd - yd)/2;
            ans.back().first += up - x[i-1];
            ans.push_back(make_pair(x[i] - up, '-'));
        }
        else if(dir == 2) ans.back().first += x[i] - x[i-1];
        else{
            int up = x[i] - (xd + yd) / 2;
            ans.back().first += up - x[i-1];
            ans.push_back(make_pair(x[i] - up, '+'));
        }
    }
    return ans;
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d %d", &x[i], &y[i]);
        if((x[i] + y[i] + 1000000000) % 2 || abs(x[i] - x[i-1]) < abs(y[i] - y[i-1])){
            printf("-1");
            return 0;
        }
    }

    ans = solve();
    for(int i=1; i<=n; i++) y[i] = -y[i];
    auto tmp = solve();
    if(ans.size() > tmp.size()){
        ans = tmp;
        for(auto p: ans) p.second ^= '+' ^ '-';
    }

    printf("%d\n", (int)ans.size());
    for(auto p: ans){
        printf("%d %c\n", p.first, p.second);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%d %d", &x[i], &y[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Incorrect 0 ms 204 KB Point #0 (1, -1) is not covered by the answer
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Incorrect 0 ms 204 KB Point #0 (1, -1) is not covered by the answer
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Incorrect 0 ms 204 KB Point #0 (1, -1) is not covered by the answer
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB OK, n=5 ans=3
2 Correct 0 ms 204 KB OK, n=10 ans=4
3 Incorrect 1 ms 204 KB Point #0 (1, -1) is not covered by the answer
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Incorrect 0 ms 204 KB Point #0 (1, -1) is not covered by the answer
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB OK, n=2 ans=1
2 Incorrect 0 ms 204 KB Point #0 (1, -1) is not covered by the answer
3 Halted 0 ms 0 KB -