QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760856#9730. Elevator IIyihang_01#WA 0ms3596kbC++202.2kb2024-11-18 19:48:302024-11-18 19:48:30

Judging History

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

  • [2024-11-18 19:48:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-11-18 19:48:30]
  • 提交

answer

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <vector>
#define int long long
using namespace std;

struct node{
    int x , y;
    int id;
    node(int x , int y , int id){
        this->x = x;
        this->y = y;
        this->id = id;
    }
    bool operator < (const node &a)const{
        if(x == a.x){
            return y < a.y;
        }else{
            return x < a.x;
        }
    }
};

bool cmp(const node & a ,const node & b){
    if(a.y == b.y){
        return a.x < b.x;
    }else{
        return a.y > b.y;
    }
}

vector<node> mp;
list<node> ned1;
vector<node> ned2;

map<int , int > id_ans;


void solve(){

    mp.clear();
    ned1.clear();
    ned2.clear();
    id_ans.clear();
    

    int n , tmpx , tmpy , initf;
    int nedval = 0;
    cin >> n >> initf;
    for(int i = 1;i<=n;i++){
        cin >> tmpx >> tmpy;
        nedval += tmpy - tmpx;
        mp.push_back(node(tmpx , tmpy , i));
    }
    sort(mp.begin() , mp.end());
    for(int i = 0;i<n;i++){
        if(mp[i].y >= initf)
            ned1.push_back(mp[i]);
        else
            ned2.push_back(mp[i]);
    }
    int nowend = initf;
    int extraval = 0;
    for(auto it = ned1.begin();it!= ned1.end() ;){
        int ittx = it->x;
        int itty = it->y;
        int ittid = it->id;
        if(itty <= nowend){
            ned2.push_back(node(ittx, itty , ittid));
            it = ned1.erase(it);
            continue;
        }
        if(nowend < ittx){
            extraval += ittx - nowend;
        }
        nowend = itty;
        it ++ ;
    }

    sort(ned2.begin() , ned2.end() , cmp);
    int ans = 0;
    for(auto it : ned1){
        id_ans[it.id] = ++ans;
    }
    for(auto it : ned2){
        id_ans[it.id] = ++ans;
    }
    cout << nedval + extraval << endl;
    for(int i = 1;i<=n;i++){
        cout << id_ans[i] << " ";
    }
    cout <<endl;
    return ;

}

signed main(){
    int t;
    ios::sync_with_stdio(0);
    cin.tie(0) , cout.tie(0);
    cin >> t;
    while(t--){
        solve();
    }
    
}
/*
2
4 2
3 6
1 3
2 7
4 5 
2 5
2 4
6 8
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3596kb

input:

2
4 2
3 6
1 3
2 7
5 6
2 5
2 4
6 8

output:

11
3 1 2 4 
5
2 1 

result:

wrong answer Participant declares the cost to be 11, but the plan actually costs 13 (test case 1)