QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#510019#5450. 比赛Antekb6 3ms3844kbC++144.8kb2024-08-08 20:36:232024-08-08 20:36:24

Judging History

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

  • [2024-08-08 20:36:24]
  • 评测
  • 测评结果:6
  • 用时:3ms
  • 内存:3844kb
  • [2024-08-08 20:36:23]
  • 提交

answer

#include "bits/stdc++.h"	/** keep-include */
using namespace std;

#define rep(i, b, e) for(int i = (b); i <= (e); i++)
#define per(i, b, e) for(int i = (e); i >= (b); i--)
#define FOR(i, b, e) rep(i, b, (e) - 1)
#define SZ(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

auto &operator<<(auto &o, pair<auto, auto> p) {
	return o << "(" << p.st << ", " << p.nd << ")"; }
auto operator<<(auto &o, auto x)->decltype(end(x), o) {
	o << "{"; int i=0; for(auto e: x) o << ", " + 2*!i++ << e;
	return o << "}"; }
#ifdef LOCAL
#define deb(x...) cerr << "[" #x "]: ", [](auto...$) { \
	((cerr << $ << "; "),...) << endl; }(x)
#else
#define deb(...)
#endif

const int N=2005;

bool good(vector<int> V, vector<vector<vi> > &common){
    for(int i=0; i<V.size(); i++)
    {
        int a=V[i], b=V[(i+1)%V.size()], c=V[(i+2)%V.size()];
        for(int j:common[a][b]){
            if(binary_search(all(common[b][c]), j)){
                return 0;
            }
        }
    }
    return 1;
}

bool good2(vector<int> V, vector<vector<vi> > &common){
    for(int i=0; i<V.size()-2; i++)
    {
        int a=V[i], b=V[i+1], c=V[i];
        for(int j:common[a][b]){
            if(binary_search(all(common[b][c]), j)){
                return 0;
            }
        }
    }
    return 1;
}


void solve() {
    int n, m;
    cin>>n>>m;
    vector<vi> V(m);
    vector<vector<vi> > common(n, vector<vi>(n, vi(0)));
    vector<bitset<N> > kto(m);
    int maks=0;
    for(int i=0; i<m; i++){
        int k;
        cin>>k;
        maks=max(maks, k);
        V[i].resize(k);
        for(int &j:V[i]){
            cin>>j;
            j--;
            kto[i][j]=1; 
        }
        for(int &j:V[i]){
            for(int &l:V[i]){
                common[j][l].pb(i);
            }
        }
    }
    if(maks>(2*n)/3){
        cout<<-1<<"\n";
        return;
    }
    vector<int> kol;
    for(int ii=1; ii<=n; ii++){
        deb(V, kol);
        bitset<N> zle;
        zle.flip();
        for(int j:kol)zle[j]=0;
        if(ii<=n-3){
            for(int i=0; i<m; i++){
                if(kto[i].count()>(2*(n-ii))/3){
                    zle&=kto[i];
                }
            }
        }
        assert(zle.any());
        int t=zle._Find_first();
        kol.pb(t);
        for(int i=0; i<m; i++){
            kto[i][t]=0;
        }
    }
    vector<int> dobre;
    for(int i=0; i<3; i++){
        dobre.pb(kol.back());
        kol.pop_back();
    }
    while(kol.size()){
        deb(kol, dobre);
        bool ok=0;
        if(dobre.size()<10){
            for(int i=0; i<dobre.size(); i++){
                deb("b");
                vector<int> dobre2;
                dobre2=dobre;
                rotate(dobre2.begin(), dobre2.begin()+i, dobre2.end());
                dobre2.pb(kol.back());
                rotate(dobre2.begin(), dobre2.end()-2, dobre2.end());
                auto it=dobre2.begin(), it2=dobre2.begin()+5;
                if(dobre2.size()<5)it2=dobre2.end();
                sort(it, it2);
                deb("a");
                while(true){
                    if(good(dobre2, common)){
                        ok=1;
                        break;
                    }
                    if(!next_permutation(it, it2))break;
                }
                if(ok==1){
                    dobre=dobre2;
                    break;
                }
            }
        }
        else{
            for(int i=0; i<dobre.size(); i++){
                vector<int> V;
                for(int k=-3; k<=4; k++){
                    V.pb(dobre[(i+dobre.size()-k)%dobre.size()]);
                    if(k==0){
                        V.pb(kol.back());
                    }
                }
                auto it=V.begin()+2, it2=V.begin()+7;
                sort(it, it2);
                while(true){
                    if(good2(V, common)){
                        ok=1;
                        break;
                    }
                    if(!next_permutation(it, it2))break;
                }
                if(ok==1){
                    for(int k=-3; k<=4; k++){
                        dobre[(i+dobre.size()-k)%dobre.size()]=V[k];
                    }
                    dobre.insert(dobre.begin()+(i+5)%int(dobre.size()), V.back());
                    break;
                }
            }
        }
        assert(ok==1);
        kol.pop_back();
    }
    assert(good(dobre, common));
    for(int i:dobre){
        cout<<i+1<<" ";
    }
    cout<<"\n";
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int tt = 1;
    cin>>tt;
	FOR(te, 0, tt) solve();
	return 0;
}

详细

Subtask #1:

score: 6
Accepted

Test #1:

score: 6
Accepted
time: 2ms
memory: 3556kb

input:

248
9 3
3 3 4 5
3 1 2 3
4 6 7 8 9
8 1
4 3 4 5 6
9 2
5 1 2 3 4 5
3 6 7 8
6 1
4 3 4 5 6
7 2
3 3 4 5
3 1 2 3
9 3
4 1 2 3 4
3 4 5 6
3 6 7 8
7 1
4 4 5 6 7
8 2
3 6 7 8
3 2 3 4
8 2
4 1 2 3 4
4 4 5 6 7
3 0
9 3
3 2 3 4
3 7 8 9
3 4 5 6
6 1
5 1 2 3 4 5
9 2
4 1 2 3 4
3 6 7 8
9 3
3 6 7 8
3 3 4 5
3 1 2 3
8 1
8 1 ...

output:

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

result:

ok 248 testcases

Test #2:

score: 6
Accepted
time: 2ms
memory: 3628kb

input:

180
6 3
3 1 2 3
3 3 4 5
3 1 5 6
6 3
3 5 1 3
3 2 3 4
3 1 6 4
6 2
4 2 6 1 4
3 3 6 5
6 2
4 2 1 4 5
3 6 2 3
6 4
3 5 6 3
3 5 1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 2 1 
-1
1 3 4 2 6 7 8 5 
...

result:

ok 339 testcases

Test #7:

score: 6
Accepted
time: 0ms
memory: 3644kb

input:

336
8 5
3 8 4 7
3 2 4 3
4 1 8 5 3
3 6 5 4
4 6 2 1 7
3 1
3 1 2 3
4 1
3 2 1 3
9 4
3 8 4 3
6 1 7 6 2 4 5
3 3 9 1
3 9 8 6
7 4
4 4 6 7 3
3 1 7 5
3 5 6 2
3 4 2 1
4 0
3 1
3 3 2 1
8 2
4 6 3 5 4
5 3 8 2 1 7
3 0
7 4
3 5 3 1
3 4 1 7
4 6 4 2 5
3 7 6 3
7 4
4 5 4 2 3
3 6 7 4
3 7 2 1
3 6 1 5
4 0
7 4
3 5 4 2
4 7 2 ...

output:

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

result:

ok 336 testcases

Subtask #2:

score: 0
Runtime Error

Dependency #1:

100%
Accepted

Test #8:

score: 0
Runtime Error

input:

2
12 3
7 1 3 4 8 9 11 12
3 1 5 6
3 6 7 12
15 1
10 1 2 3 4 5 6 7 8 9 10

output:


result:


Subtask #3:

score: 0
Runtime Error

Dependency #1:

100%
Accepted

Test #17:

score: 0
Runtime Error

input:

66
43 106
3 42 1 38
4 3 16 13 39
3 42 37 8
3 5 2 37
3 35 40 19
4 8 10 6 12
3 2 42 32
3 8 28 5
3 37 11 31
3 35 1 30
3 12 24 26
5 13 1 5 12 36
3 24 37 43
4 16 34 20 17
3 34 30 2
3 16 1 10
3 20 3 19
3 28 31 35
3 2 27 3
4 36 16 24 30
3 7 4 24
3 41 14 31
3 23 14 16
4 36 26 17 42
3 29 37 3
3 1 40 3
3 20 2...

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #25:

score: 0
Runtime Error

input:

5
400 1
266 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #36:

score: 0
Runtime Error

input:

5
400 1
266 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #4:

0%

Subtask #8:

score: 0
Skipped

Dependency #5:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%