QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#466059#8818. Colorful Graph 3HKOI0#WA 15ms3572kbC++171.7kb2024-07-07 15:22:442024-07-07 15:22:45

Judging History

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

  • [2024-07-07 15:22:45]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3572kb
  • [2024-07-07 15:22:44]
  • 提交

answer

#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

void solve() {
    int n,k;
    cin>>n>>k;
    vector<int> c(k);
    int idx=-1;
    for(int i=0;i<k;i++) {
        auto& x=c[i];
        cin>>x;
        if(x>=2) idx=i;
    }
    vector<tuple<int,int,int>> ans;
    if(idx!=-1) {
        for(int i=1;i<n;i++) ans.emplace_back(0,i,idx);
    }
    else {
        vector<int> p;
        for(int i=0;i<k;i++)
            if(c[i]==1) p.emplace_back(i);
        if(sz(p)>=n-1) {
            for(int i=1;i<n;i++) ans.emplace_back(0,i,p[i-1]);
        }
        else {
            vector<int> nums;
            vector<bool> used(k);
            for(auto i:p) {
                used[i]=true;
                for(int j=0;j<3;j++) nums.emplace_back(i);
            }
            for(int i=0;i<k;i++)
                if(!used[i]) nums.emplace_back(i);
            if(sz(nums)>n) nums.resize(n);
            for(int i=0;i<sz(nums)-1;i++) ans.emplace_back(i,i+1,nums[i]);
            ans.emplace_back(sz(nums)-1,0,nums.back());
            for(int i=sz(nums);i<n;i+=k-1) {
                int ed=min(n,i+k-1)-1;
                ans.emplace_back(0,i,0);
                for(int j=i;j<ed;j++) ans.emplace_back(j,j+1,j-i+1);
                ans.emplace_back(ed,0,ed-i+1);
            }
        }
    }
    cout<<sz(ans)<<'\n';
    for(auto [u,v,w]:ans) cout<<u+1<<' '<<v+1<<' '<<w+1<<'\n';
}

signed main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

input:

3
4 2
1 1
2 2
0 0
5 2
3 1

output:

4
1 2 1
2 3 1
3 4 1
4 1 2
2
1 2 1
2 1 2
4
1 2 1
1 3 1
1 4 1
1 5 1

result:

ok orz (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 15ms
memory: 3572kb

input:

4645
2 2
0 0
2 2
0 1
2 2
1 1
3 2
0 0
3 2
0 1
3 2
1 1
3 3
0 0 0
3 3
1 0 0
3 3
1 0 1
3 3
1 1 1
4 2
0 0
4 2
1 0
4 2
1 1
4 3
0 0 0
4 3
0 0 1
4 3
0 1 1
4 3
1 1 1
4 4
0 0 0 0
4 4
0 1 0 0
4 4
1 1 0 0
4 4
1 1 1 0
4 4
1 1 1 1
5 2
0 0
5 2
1 0
5 2
1 1
5 3
0 0 0
5 3
0 1 0
5 3
1 1 0
5 3
1 1 1
5 4
0 0 0 0
5 4
0 1...

output:

2
1 2 1
2 1 2
1
1 2 2
1
1 2 1
4
1 2 1
2 1 2
1 3 1
3 1 2
3
1 2 2
2 3 2
3 1 2
2
1 2 1
1 3 2
3
1 2 1
2 3 2
3 1 3
3
1 2 1
2 3 1
3 1 1
2
1 2 1
1 3 3
2
1 2 1
1 3 2
6
1 2 1
2 1 2
1 3 1
3 1 2
1 4 1
4 1 2
4
1 2 1
2 3 1
3 4 1
4 1 2
4
1 2 1
2 3 1
3 4 1
4 1 2
5
1 2 1
2 3 2
3 1 3
1 4 1
4 1 2
4
1 2 3
2 3 3
3 4 3
...

result:

wrong answer your solution is suboptimal (test case 67)