QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#719400#4740. Plan metranathan46900 0ms0kbC++173.0kb2024-11-07 00:40:082024-11-07 00:40:11

Judging History

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

  • [2024-11-07 00:40:11]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-11-07 00:40:08]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define el cout << '\n'
#define f1(i,n) for(int i=1;i<=n;i++)
#define __file_name ""
using namespace std;
const ll maxn = 4e6+5, inf=1e18;

struct Edge{
    int u, v, w;
    Edge(){};
    Edge(int u, int v, int w): u(u), v(v), w(w){};
};

int n,d[maxn], l[maxn];
vector<int> mp[2*maxn], allv;
vector<Edge> ans;

bool cmp(int x, int y){
    return d[x] < d[y];
}

bool solve(int duv){
    for(int item: allv){
        mp[item + maxn].clear();
    }
    allv.clear();
    ans.clear();
    for(int i=2;i<n;i++){
        int diff = d[i] - l[i];
        if(mp[diff + maxn].empty()) allv.push_back(diff);
        mp[diff + maxn].push_back(i);
    }
//    int duv = 1e9;
//    for(int i=2;i<n;i++) duv = min(duv, d[i] + l[i]);
//    if(abs(*allv.begin()) == abs(*allv.rbegin()) && allv.size() <= 2) duv = abs(*allv.begin());
    if(mp[duv+maxn].empty()) allv.push_back(duv);
    if(mp[-duv+maxn].empty()) allv.push_back(-duv);
    mp[-duv+maxn].push_back(1); l[1] = duv;
    mp[duv+maxn].push_back(n); d[n] = duv;
    int rem2 = allv[0] & 1;
    for(int item: allv) {
        if((item & 1) != rem2) return false;
        sort(mp[item + maxn].begin(), mp[item + maxn].end(), cmp);
    }
    sort(allv.begin(), allv.end());
    int pre = 1, dst = 0;
    for(int item: allv){
        int u = mp[item + maxn][0];
//        cout << item << ' ' << u << ' ' << d[u] << ' ' << dst << endl;
//        for(Edge e: ans){
//            cout << e.u << ' ' << e.v << ' ' << e.w << '\n';
//        }
        if(u > 1){
            if(dst >= d[u]) return false;
            ans.push_back(Edge(pre, u, d[u] - dst));
            dst = d[u];
            if(duv - dst != l[u]) return false;
            pre = u;
        }
        if(dst > duv) return false;
        // int dst2 = dst;
        for(int i=1;i<mp[item+maxn].size();i++){
            int v = mp[item+maxn][i];
            if(d[v] <= dst) return false;
            ans.push_back(Edge(u, v, d[v] - dst));
            if(duv - dst + (d[v] - dst) != l[v]) return false;
        }
    }
    cout << "TAK\n";
    for(Edge e: ans){
        cout << e.u << ' ' << e.v << ' ' << e.w << '\n';
    }
    return true;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    if(fopen(__file_name ".inp", "r")){
        freopen(__file_name ".inp","r",stdin);
        freopen(__file_name ".out","w",stdout);
    }
    // code here
    cin >> n;
    if(n == 2){
        cout << "TAK\n1 2 1\n";
        return 0;
    }
    for(int i=2;i<n;i++) cin >> d[i];
    for(int i=2;i<n;i++) cin >> l[i];
    for(int i=2;i<n;i++){
        int diff = d[i] - l[i];
        if(mp[diff + maxn].empty()) allv.push_back(diff);
        mp[diff + maxn].push_back(i);
    }
    sort(allv.begin(), allv.end());
    int duv = 1e9, duv2 = 1;
    for(int i=2;i<n;i++) duv = min(duv, d[i] + l[i]);
    duv2 = abs(*allv.begin());
    if(solve(duv)) return 0;
    if(solve(duv2)) return 0;
    cout << "NIE\n";
    return 0;
}

详细

Subtask #1:

score: 0
Memory Limit Exceeded

Test #1:

score: 0
Memory Limit Exceeded

input:

7
6 6 2 2 1
5 3 5 1 4

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%