QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#563917#8589. ExplosivesMathModel0 0ms3640kbC++141.9kb2024-09-14 17:18:582024-09-14 17:18:59

Judging History

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

  • [2024-09-14 17:18:59]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3640kb
  • [2024-09-14 17:18:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

void burn() {
    ios::sync_with_stdio(0);
    cin.tie(0);
}
int C(const vector<int>& operations, const vector<int>& a, const vector<int>& b) {
    int current_location = 0; 
    int explosives = 0;       
    int total_cost = 0;       

    unordered_set<int> factories(a.begin(), a.end()); 
    unordered_set<int> mines(b.begin(), b.end());     

    for (int i = 0; i < operations.size(); i++) {
        int next_location = operations[i];
        
        int distance = abs(next_location - current_location);

        if (explosives > 0) {
            total_cost += distance;
        }
        
        current_location = next_location;

        if (factories.count(next_location)) {
            explosives++;  
        } else if (mines.count(next_location)) {
            explosives--;  
        }
    }

    return total_cost;
}


void solve() {
    int n, c;
    cin >> n >> c;
    vector<int> a(n), b(n);
    vector<int> all(2 * n);
    
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        a[i] = x;
        all[i] = x;
    }
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        b[i] = x;
        all[n + i] = x;
    }

    sort(all.begin(), all.end());

    vector<int> x, y, z;

    for (int i = 0; i < n - 1; i++) {
        x.push_back(all[i]);
    }
    for (int i = n - 1; i < 2 * n - 2; i++) {
        z.push_back(all[i]);
    }
    reverse(z.begin(), z.end()); 
    y.push_back(all[2 * n - 1]);
    y.push_back(all[2 * n - 2]);
    vector<int> finale;
    finale.reserve(2 * n);  
    finale.insert(finale.end(), x.begin(), x.end()); 
    finale.insert(finale.end(), y.begin(), y.end()); 
    finale.insert(finale.end(), z.begin(), z.end()); 

    cout << C(finale,a,b) << "\n";

    for (auto i : finale) {
        cout << i << " ";
    }
    cout << "\n";
}

int main() {
    burn();
    solve();
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

1 1
149
6236

output:

0
6236 149 

result:

wrong answer no candy to unload on operation 0

Subtask #2:

score: 0
Wrong Answer

Test #8:

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

input:

4 5
4701 3171 4420 3458
9318 8156 6845 5547

output:

8620
3171 3458 4420 9318 8156 6845 5547 4701 

result:

wrong answer no candy to unload on operation 6

Subtask #3:

score: 0
Skipped

Dependency #1:

0%