QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#121441#1146. Railsomethingnew#Compile Error//C++207.0kb2023-07-08 06:51:312024-07-04 00:30:37

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:30:37]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-08 06:51:31]
  • 提交

answer

//  ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
//  ➡ @roadfromroi ⬅
//  ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include <unistd.h>
#include "array"
#include "set"
#define all(x) x.begin(), x.end()
using namespace std;
/* This is sample grader for the contestant getDistance*/
#include "rail.h"
int getdst(int frst, int x, int fromleft, set<pair<int, int>> &lftcnt, set<pair<int, int>> &rgtcnt) {
    if (fromleft) {
        if (frst <= x) {
            return x - frst;
        } else {
            auto it1 = lftcnt.lower_bound({frst, 0});
            if (it1 == lftcnt.end())
                return -1;
            pair<int, int> pos = *it1;
            int res = pos.first - frst;
            auto it2 = rgtcnt.lower_bound({x-1, 100001});
            if (it2 == rgtcnt.begin())
                return -1;
            pair<int, int> pos2 = *(--it2);
            res += pos.first - pos2.first;
            res += x - pos2.first;
            return res;
        }
    } else {
        auto it1 = lftcnt.lower_bound({frst+1, 0});
        if (it1 == lftcnt.end())
            return -1;
        pair<int, int> pos = *it1;
        int res = pos.first - frst + pos.first - x;
        return res;
    }
}
int getdst2(int frst, int x, set<pair<int, int>> &lftcnt, set<pair<int, int>> &rgtcnt) {
    auto it1 = rgtcnt.lower_bound({x+1, 0});
    if (it1 == rgtcnt.begin())
        return -1;
    pair<int, int> pos = *(--it1);
    int res = - pos.first + frst - pos.first + x;
    return res;
}
void findLocation(int n, int first, int location[], int stype[]) {
    location[0] = first;
    stype[0] = 1;
    vector<pair<int, int>> resba;
    for (int i = 1; i < n; ++i) {
        resba.push_back({getDistance(0, i), i});
    }
    sort(all(resba));
    set<pair<int, int>> lftcnt, rgtcnt;
    rgtcnt.insert({first, 0});
    for (auto i : resba) {
        if (lftcnt.empty()) {
            lftcnt.insert({i.first + first, i.second});
            location[i.second] = i.first + first;
            stype[i.second] = 2;
        } else {
            // cout << i.first << ' ' << i.second << '\n';
            //  cout << -v2 + lftcnt.rbegin()->first << '\n';
            int v2 = getDistance(lftcnt.rbegin()->second, i.second);
            int v3 = getDistance(rgtcnt.begin()->second, i.second);
            //  cout << v2 + rgtcnt.begin()->first << '\n';
            int op1 = -v2 + lftcnt.rbegin()->first;
            int op2 = v3 + rgtcnt.begin()->first;
            bool tr1 = 1, tr2 = 1;
            if (getdst(first, op2, 1, lftcnt, rgtcnt) != i.first) {
                tr2 = 0;
            }
            if (lftcnt.rbegin()->first > op2 and getdst2(lftcnt.rbegin()->first, op2, lftcnt, rgtcnt) != v2) {
                tr2 = 0;
            }
            //cout << i.first << ' ' << first << ' ' << op1 << ' ' << getdst(first, op1, 0, lftcnt, rgtcnt) << '\n';
            if (getdst(first, op1, 0, lftcnt, rgtcnt) != i.first) {
                tr1 = 0;
            }
            if (tr2 and op2 < first and getdst(first, op2, 1, lftcnt, rgtcnt) == i.first) {
                tr1 = 0;
            }//cout << tr1 << ' ' << tr2 << '\n';
            //cout << "(" << op1 << ' ' << op2 << ")\n";
                //cout << "No\n";
            if (tr1) {
                rgtcnt.insert({op1, i.second});
                location[i.second] = op1;
                stype[i.second] = 1;
              //  cout << i.second << "->" << op1 << '\n';
              //  cout << i.second << "->" << 1 << '\n';
            } else {
                lftcnt.insert({op2, i.second});
                location[i.second] = op2;
                stype[i.second] = 2;
             //   cout << i.second << "->" << op2 << '\n';
             //   cout << i.second << "->" << 2 << '\n';
            }
        }
    }
}

typedef struct Station {
    int index;
    int type;
    int location;
    int L,R;
}STATION;
long long cnt;
static int S,SUBTASK;
static STATION stations[10004];

int cmp_fun_1(const void *a,const void *b)
{
    STATION c,d;
    c = *(STATION*)(a);
    d = *(STATION*)(b);
    return c.location < d.location ? -1 : 1;
}

int cmp_fun_2(const void *a,const void *b)
{
    STATION c,d;
    c = *(STATION*)(a);
    d = *(STATION*)(b);
    return c.index < d.index ? -1 : 1;
}

void now_I_want_to_getLR(){
    int now = stations[S-1].index,i;
    for(i=S-2;i>=0;i--){
        stations[i].R = now;
        if(stations[i].type==2)	now = stations[i].index;
    }
    now = stations[0].index;
    for(i=1;i<S;i++){
        stations[i].L = now;
        if(stations[i].type==1)	now = stations[i].index;
    }
}

int getDistance(int x,int y)
{
    cnt++;
    if(x==y)	return 0;
    if(x<0 || x>=S || y<0 || y>=S)    return -1;
    if(stations[x].location > stations[y].location){
        int tmp = x;
        x = y;
        y = tmp;
    }
    int ret = 0;
    if(stations[x].type==1 && stations[y].type==1){
        ret = stations[stations[y].R].location-stations[x].location+stations[stations[y].R].location-stations[y].location;
    }else if(stations[x].type==1 && stations[y].type==2){
        ret = stations[y].location-stations[x].location;
    }else if(stations[x].type==2 && stations[y].type==2){
        ret = stations[x].location-stations[stations[x].L].location+stations[y].location-stations[stations[x].L].location;
    }else if(stations[x].type==2 && stations[y].type==1){
        ret = stations[x].location-stations[stations[x].L].location+stations[stations[y].R].location
              -stations[stations[x].L].location+stations[stations[y].R].location-stations[y].location;
    }
    return ret;
}


void getInput()
{
    int g;
    g = scanf("%d",&SUBTASK);
    g = scanf("%d",&S);
    int s;
    for (s = 0; s < S; s++) {
        int type, location;
        g = scanf(" %d %d",&type,&location);
        stations[s].index = s;
        stations[s].location = location;
        stations[s].type = type;
        stations[s].L = -1;
        stations[s].R = -1;
    }
    qsort(stations, S, sizeof(STATION), cmp_fun_1);
    now_I_want_to_getLR();
    qsort(stations, S, sizeof(STATION), cmp_fun_2);
}

int serverGetStationNumber()
{
    return S;
}

int serverGetSubtaskNumber()
{
    return SUBTASK;
}

int serverGetFirstStationLocation()
{
    return stations[0].location;
}

int main()
{
    int i;
    getInput();
    cnt = 0;

    int location[10005];
    int type[10005];
    int ok = 1;
    findLocation(S, serverGetFirstStationLocation(),location, type);
    if(SUBTASK==3 && cnt>S*(S-1))	ok = 0;
    if(SUBTASK==4 && cnt>3*(S-1))	ok = 0;


    for (i = 0; i < S; i++)
        if(type[i]!=stations[i].type || location[i]!=stations[i].location)
            ok = 0;
    if(ok==0)	printf("Incorrect");
    else	printf("Correct");
    return 0;
}
/*
3
6
1 5
1 1
2 12
2 2
1 3
2 4
2 6
1 6
2 8
1 9
2 10
1 11
 */

详细

/usr/bin/ld: /tmp/ccbAQDka.o: in function `now_I_want_to_getLR()':
answer.code:(.text+0x860): multiple definition of `now_I_want_to_getLR()'; /tmp/ccDzZZpa.o:implementer.cpp:(.text+0x20): first defined here
/usr/bin/ld: /tmp/ccbAQDka.o: in function `getDistance':
answer.code:(.text+0x900): multiple definition of `getDistance'; /tmp/ccDzZZpa.o:implementer.cpp:(.text+0xc0): first defined here
/usr/bin/ld: /tmp/ccbAQDka.o:(.bss+0x0): multiple definition of `cnt'; /tmp/ccDzZZpa.o:(.bss+0x0): first defined here
/usr/bin/ld: /tmp/ccbAQDka.o: in function `getInput()':
answer.code:(.text+0xa40): multiple definition of `getInput()'; /tmp/ccDzZZpa.o:implementer.cpp:(.text+0x230): first defined here
/usr/bin/ld: /tmp/ccbAQDka.o: in function `serverGetStationNumber()':
answer.code:(.text+0xb60): multiple definition of `serverGetStationNumber()'; /tmp/ccDzZZpa.o:implementer.cpp:(.text+0x200): first defined here
/usr/bin/ld: /tmp/ccbAQDka.o: in function `serverGetSubtaskNumber()':
answer.code:(.text+0xb70): multiple definition of `serverGetSubtaskNumber()'; /tmp/ccDzZZpa.o:implementer.cpp:(.text+0x210): first defined here
/usr/bin/ld: /tmp/ccbAQDka.o: in function `serverGetFirstStationLocation()':
answer.code:(.text+0xb80): multiple definition of `serverGetFirstStationLocation()'; /tmp/ccDzZZpa.o:implementer.cpp:(.text+0x220): first defined here
/usr/bin/ld: /tmp/ccbAQDka.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/ccDzZZpa.o:implementer.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status