제출 #636250

#제출 시각아이디문제언어결과실행 시간메모리
636250Ronin13Xylophone (JOI18_xylophone)C++14
100 / 100
107 ms1084 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;



void solve(int N) {
    int n = N;
    vector <int> last;
    last.pb(0);
    last.pb(query(1, 2));
    for(int i = 3; i <= n; i++){
        int x = query(i - 1, i);
        int y = query(i - 2, i);
        int l = last.back() / (abs(last.back()));
        if(y == x + abs(last.back())) last.pb(x * l);
        else last.pb(-x * l);
    }

    map<int, int> used;
    used[0] = true;
    int pref = 0;
    int ind;
    for(int i = 1; i < last.size(); i++){
        pref += last[i];
        if(used[pref - (n - 1)]){
            ind = i;
            break;
        }
        if(used[pref - (1 - n)]){
            ind = i;
            break;
        }
        used[pref] = true;
    }
    if(last[ind] < 0){
        for(int i = 0; i < last.size(); i++) last[i] *= (-1);
    }
   // answer(ind + 1, n);
    int a[n + 1];
    a[ind + 1] = n;
    for(int i = ind; i >= 0; i--){
        int x = last[i];
        a[i] = a[i + 1] - x;

    //    answer(i, a[i]);
    }
    for(int i = ind + 2; i <= n; i++){
        int x = last[i - 1];
        a[i] = a[i - 1] + x;
       // answer(i, a[i]);
    }

    for(int i = 1; i <= n; i++) answer(i, a[i]);
}

컴파일 시 표준 에러 (stderr) 메시지

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i = 1; i < last.size(); i++){
      |                    ~~^~~~~~~~~~~~~
xylophone.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(int i = 0; i < last.size(); i++) last[i] *= (-1);
      |                        ~~^~~~~~~~~~~~~
xylophone.cpp:43:16: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |     if(last[ind] < 0){
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...