답안 #333794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333794 2020-12-07T19:35:28 Z Swan Xylophone (JOI18_xylophone) C++14
컴파일 오류
0 ms 0 KB
#include "xylophone.h"
#include <bits/stdc++.h>
#define stop system("pause")
#define INP freopen("snowcow.in","r",stdin)
#define OUTP freopen("snowcow.out","w",stdout)

using namespace std;


void check(vector<int>& signSwap, vector<int>& diff, int sign){
    int startSign = sign;
    int now = sign * diff[0];
    int one = 0;
    int mn = min(0, now);
    if(now < 0){
        one = 1;
    }
    for(int i = 0; i < signSwap.size();i++){
        if(signSwap[i])sign = -sign;
        now+=sign * diff[i + 1];
        if(now < mn){
            mn = now;
            one = i + 2;
        }
    }
    vector<int> ans;
    int ansSize = diff.size() + 1;
    ans.resize(ansSize);
    ans[one] = 1;
    sign = -1;
    for(int i = one + 1;i < ansSize; i++){
        if(signSwap[i - 2])sign = -sign;
        ans[i] = ans[i - 1] + diff[i - 1] * sign;
        if(ans[i] > ansSize || ans[i] <= 0){
            return;
        }
    }
    sign = -1;
    for(int i = one - 1;i >= 0; i--){
        if(signSwap[i])sign = -sign;
        ans[i] = ans[i + 1] + diff[i] * sign;
        if(ans[i] > ansSize || ans[i] <= 0 || ans[i] == ansSize){
            return;
        }
    }
    answer(ans);
    exit(0);
}

void solve(int n){
    vector<int> two;
    vector<int> three;
    for(int l = 0; l < n - 1;l++){
        two.push_back(query(l, l + 1));
        if(l + 2 < n)three.push_back(query(l, l + 2));
    }
    vector<int> signSwap;
    for(int i = 0; i < two.size() - 1;i++){
        if(two[i] + two[i + 1] == three[i]){
            signSwap.push_back(0);
        }else{
            signSwap.push_back(1);
        }
    }
    check(signSwap, two, -1);
    check(signSwap, two, 1);
    return 0;
}

/*
7
2 3 4 1 5 7 6
5
1 4 2 3 5
8
6 2 3 1 8 5 4 7
3
1 2 3
3
2 1 3
9
5 7 8 2 3 1 9 6 4
*/

Compilation message

xylophone.cpp: In function 'void check(std::vector<int>&, std::vector<int>&, int)':
xylophone.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i = 0; i < signSwap.size();i++){
      |                    ~~^~~~~~~~~~~~~~~~~
xylophone.cpp:46:12: error: cannot convert 'std::vector<int>' to 'int'
   46 |     answer(ans);
      |            ^~~
      |            |
      |            std::vector<int>
In file included from xylophone.cpp:1:
xylophone.h:5:17: note:   initializing argument 1 of 'void answer(int, int)'
    5 | void answer(int i, int a);
      |             ~~~~^
xylophone.cpp:11:9: warning: unused variable 'startSign' [-Wunused-variable]
   11 |     int startSign = sign;
      |         ^~~~~~~~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i = 0; i < two.size() - 1;i++){
      |                    ~~^~~~~~~~~~~~~~~~
xylophone.cpp:67:12: error: return-statement with a value, in function returning 'void' [-fpermissive]
   67 |     return 0;
      |            ^