QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#23564#2541. Coins and BoxesSorting#WA 44ms7692kbC++201.4kb2022-03-17 20:00:102022-04-30 03:31:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 03:31:32]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:7692kb
  • [2022-03-17 20:00:10]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
template<class T> void check_min(T &a, const T &b){ a = (a < b) ? a : b; }
template<class T> void check_max(T &a, const T &b){ a = (a > b) ? a : b; }
#define all(x) (x).begin(), (x).end()

const int N = 1e5 + 3;
const ll INF = 1e18;

ll n, b[N], c[N];
pair<ll, bool> events[2 * N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> events[i].first;
        events[i].second = 1;
    }
    for(int i = 0; i < n; ++i){
        cin >> events[i + n].first;
        events[i + n].second = 0;
    }

    sort(events, events + 2 * n);

    stack<ll> st;
    ll cnt = 0, ans = 0, min_ans = INF;
    for(ll i = 0; i < 2 * n; ++i){
        auto [x, type] = events[i];
        if(st.empty()) check_min(min_ans, events[2 * n - 1].first - x + ans);
        if(!type){
            ++cnt;
            if(cnt >= st.size() && !st.empty()){
                cnt -= st.size();
                ans += (x - st.top()) * 2;
                while(!st.empty())
                    st.pop();
            }
        }
        else{
            if(st.empty() && cnt){
                --cnt;
            }
            else st.push(x);
        }
    }
    check_min(ans, min_ans);
    ans += events[2 * n - 1].first;

    cout << ans << "\n";
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3620kb

input:

4
1 6 7 12
3 5 10 11

output:

21

result:

ok answer is '21'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3568kb

input:

2
1 2
1 1000000000

output:

1999999998

result:

ok answer is '1999999998'

Test #3:

score: -100
Wrong Answer
time: 44ms
memory: 7692kb

input:

100000
967 3246 9492 10300 15195 16650 26911 54855 83695 112841 125511 137160 153051 155859 177924 187843 214838 219388 247276 249612 250188 253873 257830 261805 281312 297030 298332 325904 333218 339683 374111 387794 396645 403705 426710 436137 463368 481801 501933 509267 511332 515225 515629 51686...

output:

1004634171

result:

wrong answer expected '1722240547', found '1004634171'