제출 #302148

#제출 시각아이디문제언어결과실행 시간메모리
302148peti1234Rail (IOI14_rail)C++17
100 / 100
105 ms760 KiB
#include <bits/stdc++.h>
#include "rail.h"
using namespace std;
const int c=5002;
int a[c], b[c], pos=1, js, bs, el, id, x, kt;
vector<int> regi;
vector<pair<int, int> > bal, jobb;
int tav(int a, int b) {
    return getDistance(a, b);
/*
    cout << a << " " << b << "\n";
    int x; cin >> x;
    return x;
*/
}
void findLocation(int n, int first, int location[], int stype[]) {
    for (int i=1; i<n; i++) {
        a[i]=tav(0, i);
        if (a[i]<a[pos]) pos=i;
    }
    location[0]=first, location[pos]=location[0]+a[pos], stype[0]=1, stype[pos]=2, kt=a[pos];
    for (int i=1; i<n; i++) {
        if (i!=pos) {
            b[i]=tav(pos, i);
            kt=min(kt, b[i]);
        }
    }
    for (int i=1; i<n; i++) {
        if (i!=pos) {
            if (a[i]+2*kt==b[i]+a[pos]) jobb.push_back({a[i], i});
            else bal.push_back({b[i], i});
        }
    }
    sort(jobb.begin(), jobb.end()), sort(bal.begin(), bal.end());
    js=jobb.size(), bs=bal.size();
    //cout << "darab " << bs << endl;
    if (js) {
        id=jobb[0].second, el=id;
        stype[id]=2, location[id]=location[0]+a[id];
        regi.push_back(id);
        for (int i=1; i<js; i++) {
            id=jobb[i].second, x=tav(el, id);
            bool jo=0;
            for (int i=0; i<regi.size(); i++) {

                if (a[el]+x-2*(location[el]-location[regi[i]])==a[id]) jo=1;
            }
            if (jo) {
                stype[id]=1, location[id]=location[el]-x;
            } else stype[id]=2, location[id]=location[0]+a[id], el=id, regi.push_back(id);
        }
    }
    regi.clear();
    if (bs) {
        id=bal[0].second, el=id;
        stype[id]=1, location[id]=location[pos]-b[id];
        regi.push_back(id);
        for (int i=1; i<bs; i++) {
            id=bal[i].second, x=tav(el, id);
            bool jo=0;
            for (int i=0; i<regi.size(); i++) {
                if (b[el]+x-2*(location[regi[i]]-location[el])==b[id]) jo=1;
            }
            if (jo) {
                stype[id]=2, location[id]=location[el]+x;
            } else stype[id]=1, location[id]=location[pos]-b[id], el=id, regi.push_back(id);
        }
    }
    //for (int i=0; i<n; i++) cout << location[i] << " " << stype[i] << "\n";
    return;
}

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

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:44:28: 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<regi.size(); i++) {
      |                           ~^~~~~~~~~~~~
rail.cpp:61:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             for (int i=0; i<regi.size(); i++) {
      |                           ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...