QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#262162#7750. Revenge on My Bossucup-team1508WA 157ms8496kbC++202.2kb2023-11-23 16:13:142023-11-23 16:13:15

Judging History

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

  • [2023-11-23 16:13:15]
  • 评测
  • 测评结果:WA
  • 用时:157ms
  • 内存:8496kb
  • [2023-11-23 16:13:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
const double eps = 1e-9;
int sgn(double x, double y) {
    if(x-y>eps) return 1;
    if(x-y<-eps) return -1;
    return 0;
}
void solve() {
    int n;
    cin >> n;
    vi a(n+1), b(n+1), c(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    vi d(n+1);
    ll B = 0;
    for (int i = 1; i <= n; i++) {
        d[i] = a[i] - b[i];
        B += b[i];
    }
    ll l = -1e9, r = 1e9;
    ll res = 0;
    vi ans(n);
    auto check = [&](ll P) -> bool {
        vector<double> e(n+1);
        for (int i = 1; i <= n; i++) {
            e[i] = 1.0 * P / c[i] - B - a[i];
        }
        
        vector<array<double,3>> tmp1;
        for (int i = 1; i <= n; i++) {
            if(d[i] < 0) tmp1.push_back(array<double,3>{e[i],1.0*d[i],1.0*i});
        } 
        sort(tmp1.begin(),tmp1.end(),greater());
        double sumd = 0;
        for (auto [e, d, id] : tmp1) {
            if(sgn(e,sumd)==-1) return false;
            sumd += d; 
        }

        vector<array<double,4>> tmp2;
        for (int i = 1; i <= n; i++) {
            if(d[i] >= 0) tmp2.push_back(array<double,4>{e[i]+d[i],1.0*d[i],e[i],1.0*i});
        } 
        sort(tmp2.begin(),tmp2.end());
        for (auto [ed, d, e, id] : tmp2) {
            if(sgn(e,sumd)==-1) return false;
            sumd += d;
        }
        for (int i = 0; i < tmp1.size(); i++) {
            ans[i] = tmp1[i][2];
        }
        for (int i = 0; i < tmp2.size(); i++) {
            ans[i + tmp1.size()] = tmp2[i][3];
        }
        return true;
    };
    while(l <= r) {
        ll md = l + r >> 1;
        if(check(md)) {
            r = md - 1;
            res = md;
        } else {
            l = md + 1;
        }
    } 
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " \n"[i == n - 1];
    }
    // cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int t;
    cin >> t;
    for (; t; t--) solve();
    
    return 0;
}

/*

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

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3492kb

input:

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

output:

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

result:

ok correct

Test #2:

score: -100
Wrong Answer
time: 157ms
memory: 8496kb

input:

1
100000
581297 102863 1
742857 42686 1
676710 233271 1
443055 491162 1
442056 28240 1
769277 331752 1
8608 369730 1
495112 525554 1
787449 938154 1
441186 850694 1
84267 925450 1
740811 32385 1
834021 37680 1
257878 564126 1
90618 914340 1
239641 463103 1
40687 343062 1
587737 458554 1
103684 48666...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer Integer parameter [name=pi] equals to 0, violates the range [1, 100000]