QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#828107#1845. PermuteZi_GaoAC ✓400ms11648kbC++202.2kb2024-12-23 13:22:022024-12-23 13:22:04

Judging History

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

  • [2024-12-23 13:22:04]
  • 评测
  • 测评结果:AC
  • 用时:400ms
  • 内存:11648kb
  • [2024-12-23 13:22:02]
  • 提交

answer

#include<bits/stdc++.h>

using i64=long long;
using u64=unsigned long long;

// #define ONLINE_JUDGE
#define INPUT_DATA_TYPE int
#define OUTPUT_DATA_TYPE int
inline __attribute((always_inline)) INPUT_DATA_TYPE read(){register INPUT_DATA_TYPE x=0;register char f=0,c=getchar();while(c<'0'||'9'<c)f=(c=='-'),c=getchar();while('0'<=c&&c<='9')x=(x<<3)+(x<<1)+(c&15),c=getchar();return f?-x:x;}void print(OUTPUT_DATA_TYPE x){if(x<0)x=-x,putchar('-');if(x>9)print(x/10);putchar(x%10^48);return;}

struct NODE{
    i64 len;
    int val;
};

i64 c[10];
int to[279936][7],pw[7];

int add(int val,int k,u64 len){
    int left=len%6;
    len-=left;
    while(left--)
        val=(val*10+k)%7;
    val=(val+(len/6)*111111*k)%7;
    return val;
}

void solve(){
    register int i,val=0,vv,s=0;
    for(i=0;i<10;++i) c[i]=read();
    for(i=7;i<10;++i) c[i-7]+=c[i];

    std::vector<NODE> res,tmp;

    for(i=6;~i;--i){
        if(c[i]>5) val=add(val,i,c[i]-5),res.push_back({c[i]-5,i}),c[i]=5;
        s=s*6+c[i];
    }
    if(to[s][val]==-1) return puts("-1"),void();

    while(s){
        res.push_back({1,to[s][val]});
        std::tie(val,s)=std::make_tuple((val*10+to[s][val])%7,s-pw[to[s][val]]);
    }

    for(auto [len,k]:res){
        if(k<=2&&c[k+7]){
            if(len<=c[k+7]) c[k+7]-=len,tmp.push_back({len,k+7});
            else tmp.push_back({c[k+7],k+7}),tmp.push_back({len-c[k+7],k}),c[k+7]=0;
        }else tmp.push_back({len,k});
    }

    printf("%d\n",tmp.size());
    for(auto [len,val]:tmp) printf("%lld %d\n",len,val);
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("name.in", "r", stdin);
	freopen("name.out", "w", stdout);
	#endif

    memset(to,-1,sizeof(to));
    register int i=0,j,s,maxs=279936;

    to[0][0]=1;

    for(i=pw[0]=1;i<7;++i) pw[i]=pw[i-1]*6;

    for(s=1;s<maxs;++s){
        c[0]+=1;
        for(i=0;i<7;++i){
            if(c[i]==6) c[i+1]+=1,c[i]=0;
            if(c[i]) for(j=0;j<7;++j)if(to[s][j]==-1&&to[s-pw[i]][(j*10+i)%7]!=-1)
                to[s][j]=i;
        }
    }

    int T=read();
    while(T--) solve();

	#ifndef ONLINE_JUDGE
	fclose(stdin);
	fclose(stdout);
	#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 11476kb

input:

3
0 1 0 0 1 0 0 0 0 0
0 2 0 0 0 0 1 0 0 1
0 1000000000 0 0 0 0 0 0 0 0

output:

2
1 1
1 4
4
1 1
1 1
1 6
1 9
-1

result:

ok T=3

Test #2:

score: 0
Accepted
time: 74ms
memory: 11636kb

input:

100000
0 0 0 1 0 1 1 1 0 1
1 1 0 0 1 0 1 0 1 0
1 1 1 1 0 0 0 1 0 1
0 1 1 0 0 1 1 1 1 0
0 0 1 0 1 0 1 0 1 0
0 1 0 0 0 0 0 1 0 0
1 1 0 0 0 0 0 0 1 1
1 0 1 1 1 0 1 0 0 0
0 1 1 0 0 1 0 1 0 1
1 0 0 1 1 0 0 1 0 0
1 1 0 1 0 0 1 0 1 1
0 0 1 0 0 0 0 1 0 0
0 1 1 1 1 1 1 1 0 1
1 0 0 0 0 1 0 0 0 1
0 0 0 0 1 0 1...

output:

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

result:

ok T=100000

Test #3:

score: 0
Accepted
time: 120ms
memory: 11372kb

input:

100000
2 1 2 1 0 1 1 0 2 0
1 2 0 1 1 2 1 1 2 1
2 2 2 1 0 2 1 1 2 2
1 1 0 2 0 2 0 1 2 0
1 0 2 2 1 2 1 0 2 2
0 1 2 2 2 1 0 2 1 2
1 1 2 0 0 1 1 0 1 0
1 0 2 2 2 0 1 0 1 1
2 1 1 2 1 0 2 0 0 1
1 0 2 2 2 0 2 1 0 1
2 0 1 1 1 1 1 1 2 1
0 1 1 0 2 0 2 0 1 2
2 1 1 0 2 0 2 1 0 1
1 2 2 2 0 2 1 1 1 0
2 0 0 2 0 2 2...

output:

10
1 0
1 0
1 8
1 8
1 1
1 2
1 2
1 3
1 5
1 6
12
1 7
1 0
1 8
1 8
1 1
1 1
1 9
1 3
1 4
1 5
1 6
1 5
15
1 7
1 0
1 0
1 8
1 8
1 1
1 1
1 9
1 9
1 2
1 2
1 5
1 5
1 3
1 6
9
1 7
1 0
1 8
1 8
1 1
1 3
1 5
1 5
1 3
13
1 0
1 8
1 8
1 9
1 9
1 2
1 2
1 3
1 3
1 5
1 4
1 5
1 6
13
1 7
1 7
1 8
1 1
1 9
1 9
1 2
1 2
1 3
1 4
1 3
1 4...

result:

ok T=100000

Test #4:

score: 0
Accepted
time: 145ms
memory: 11648kb

input:

100000
1 3 3 2 3 0 2 1 3 2
3 1 2 0 0 3 1 0 0 1
3 2 0 2 0 2 0 1 3 1
0 1 0 3 1 1 0 3 0 2
2 2 2 3 3 3 1 0 3 0
0 3 0 2 0 3 2 0 2 3
3 0 1 1 3 3 2 1 3 1
1 2 3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4
1 4
1 4
1 5
1 5
1 5
1 6
1 5
1 6
1 6
14
1 7
1 0
1 8
1 9
1 2
1 4
1 4
...

result:

ok T=100000

Test #6:

score: 0
Accepted
time: 222ms
memory: 11648kb

input:

100000
0 2 1 4 1 4 1 1 3 4
2 3 3 1 3 4 2 1 1 1
1 2 1 3 3 1 1 5 0 0
1 4 0 3 1 1 0 0 0 4
4 3 5 0 0 0 4 2 5 1
3 2 5 1 2 5 0 0 0 1
2 0 5 3 1 3 0 5 1 3
0 2 5 4 5 5 1 1 1 0
1 3 1 4 4 5 2 2 2 1
2 1 2 1 0 0 1 2 5 1
0 2 0 4 5 4 5 2 0 3
5 3 5 5 2 2 4 0 5 5
3 4 2 2 5 1 5 0 3 4
0 3 3 0 5 3 3 4 3 5
0 3 5 4 3 3 4...

output:

21
1 7
1 8
1 8
1 8
1 1
1 1
1 9
1 9
1 9
1 9
1 2
1 3
1 3
1 3
1 3
1 4
1 6
1 5
1 5
1 5
1 5
21
1 7
1 0
1 0
1 8
1 1
1 1
1 1
1 9
1 2
1 2
1 2
1 3
1 4
1 4
1 4
1 5
1 6
1 5
1 6
1 5
1 5
17
1 7
1 7
1 7
1 7
1 7
1 0
1 1
1 1
1 2
1 3
1 3
1 3
1 4
1 4
1 4
1 6
1 5
14
1 0
1 1
1 1
1 1
1 1
1 9
1 9
1 9
1 9
1 3
1 3
1 3
1 4
...

result:

ok T=100000

Test #7:

score: 0
Accepted
time: 264ms
memory: 11376kb

input:

100000
5 5 0 1 0 3 1 5 3 6
0 5 1 4 2 1 1 5 3 4
1 3 0 5 0 2 4 1 5 5
4 5 4 5 3 5 6 3 1 3
6 0 5 3 3 6 3 5 6 3
6 3 4 4 4 0 0 1 6 3
0 5 2 4 2 4 2 5 3 3
2 4 4 5 1 0 5 6 2 3
3 0 3 5 4 3 3 5 2 6
6 3 6 2 0 5 0 2 2 4
5 3 6 2 2 5 6 4 4 2
0 6 4 3 3 6 0 3 4 4
6 5 1 1 2 6 3 6 5 4
1 3 6 5 0 3 0 1 3 2
6 4 5 2 2 6 1...

output:

23
1 9
3 8
5 7
1 0
1 0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
1 1
1 9
1 9
1 9
1 9
1 9
1 5
1 5
1 3
1 6
1 5
24
3 8
1 7
1 7
1 7
1 7
1 7
1 1
1 1
1 1
1 1
1 1
1 9
1 9
1 9
1 9
1 2
1 3
1 3
1 3
1 4
1 3
1 5
1 4
1 6
24
3 8
1 7
1 0
1 8
1 8
1 1
1 1
1 1
1 9
1 9
1 9
1 9
1 9
1 3
1 3
1 3
1 3
1 3
1 5
1 6
1 6
1 6
1 5
1 6
37
1 6
...

result:

ok T=100000

Test #8:

score: 0
Accepted
time: 285ms
memory: 11396kb

input:

100000
0 1 3 6 5 0 5 1 1 4
2 3 7 4 3 2 2 3 7 7
6 4 5 6 7 0 1 7 0 1
1 6 1 2 5 2 5 6 0 2
6 3 0 4 4 5 4 0 4 1
6 4 7 4 3 0 3 5 3 7
0 4 0 0 7 0 3 1 2 4
1 2 6 2 1 0 3 1 2 5
7 3 7 4 1 6 1 3 1 5
7 1 6 4 6 5 2 2 1 5
4 1 7 3 0 3 4 1 3 6
7 5 3 3 1 6 3 5 5 1
2 5 5 7 1 2 5 6 1 6
0 0 7 2 0 0 4 7 1 1
0 5 4 1 7 1 1...

output:

25
1 3
2 9
1 7
1 8
1 1
1 9
1 9
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3
1 4
1 4
1 4
1 4
1 6
1 6
1 6
1 6
1 4
1 6
29
7 9
2 2
5 8
1 7
1 7
1 7
1 0
1 0
1 8
1 8
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 4
1 4
1 4
1 5
1 5
1 6
1 6
30
2 4
1 3
1 9
7 7
1 0
1 0
1 0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2...

result:

ok T=100000

Test #9:

score: 0
Accepted
time: 299ms
memory: 11420kb

input:

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9
1 9
1 9
1 9
1 3
1 3
1 3
1 4
1 4
1 5
1 5
1 5
1 5
1 6
1 6
1 6
1 5
1 6
1 6
32
1 6
7 9
3 2
7 8
3 1
8 7
2 0
1 0
1 0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 6
1 6
1 6
1 3
1 6
1 6
44
4 6
4 5
3 4
3 3...

result:

ok T=100000

Test #11:

score: 0
Accepted
time: 318ms
memory: 11376kb

input:

100000
0 8 3 9 3 7 10 1 5 1
7 7 2 3 5 7 4 5 2 6
6 1 7 7 6 3 4 5 10 7
7 3 3 8 9 0 1 8 1 5
0 6 1 0 5 2 0 4 7 3
9 7 7 3 1 7 8 10 8 7
4 7 3 7 0 2 2 10 0 10
8 9 5 1 4 7 4 6 4 9
1 1 7 7 8 5 7 5 3 2
3 6 6 8 4 5 5 10 3 10
10 1 7 5 1 5 6 5 9 0
9 1 0 0 0 3 6 1 0 0
5 9 9 8 10 8 1 1 1 4
2 5 10 5 7 3 7 2 4 6
1 8...

output:

33
5 6
2 5
4 3
5 8
3 1
1 7
1 1
1 1
1 1
1 1
1 1
1 9
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3
1 4
1 4
1 4
1 5
1 5
1 5
1 6
1 5
1 6
1 6
1 6
1 5
1 6
38
2 5
3 9
2 8
2 1
5 7
2 0
1 0
1 0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
1 1
1 9
1 9
1 9
1 2
1 2
1 3
1 3
1 3
1 4
1 4
1 4
1 4
1 4
1 5
1 5
1 5
1 5
1 6
1 6
1 6
1 5
1 6
39
1 4
2 3...

result:

ok T=100000

Test #12:

score: 0
Accepted
time: 400ms
memory: 11368kb

input:

100000
494719969 120370150 440274545 51278543 770105708 138663251 867692060 230246532 162623412 131761825
16498099 70750104 350416959 359532393 346253463 539196901 104480711 629723297 27266106 267471731
320561715 423589912 850677494 604957917 815663121 8935553 252297110 812216267 821793396 495865924...

output:

45
867692055 6
138663246 5
770105703 4
51278538 3
131761825 9
440274540 2
162623412 8
120370145 1
230246532 7
494719964 0
1 0
1 0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3
1 4
1 4
1 4
1 4
1 4
1 5
1 5
1 5
1 5
1 6
1 6
1 6
1 5
1 6
1 6
45
104480706 6
539196896 5
346253458 4...

result:

ok T=100000

Test #13:

score: 0
Accepted
time: 59ms
memory: 11636kb

input:

100000
1 0 0 0 0 0 738556701 0 0 0
0 376417170 0 0 0 1 0 0 0 0
0 0 0 169526540 0 1 0 0 0 0
0 0 1 0 0 0 0 0 822697278 0
0 0 0 0 121828077 0 0 0 1 0
0 994528277 0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0 0 771142048
0 0 0 0 0 77945594 0 0 1 0
1 0 0 0 963629977 0 0 0 0 0
0 0 0 1 0 805871384 0 0 0 0
0 0 0 0 306368...

output:

7
738556696 6
1 0
1 6
1 6
1 6
1 6
1 6
7
376417165 1
1 5
1 1
1 1
1 1
1 1
1 1
7
169526535 3
1 5
1 3
1 3
1 3
1 3
1 3
7
822697273 8
1 8
1 8
1 2
1 8
1 8
1 8
7
121828072 4
1 4
1 4
1 4
1 8
1 4
1 4
-1
7
771142043 9
1 9
1 9
1 6
1 9
1 9
1 9
7
77945589 5
1 5
1 8
1 5
1 5
1 5
1 5
7
963629972 4
1 4
1 0
1 4
1 4
1 ...

result:

ok T=100000

Test #14:

score: 0
Accepted
time: 86ms
memory: 11480kb

input:

100000
2 969002522 0 0 0 0 0 0 0 0
0 0 0 902830660 0 0 2 0 0 0
0 0 0 0 1 0 216346913 0 1 0
365035921 0 0 0 0 0 0 0 1 1
0 0 0 447294079 0 0 0 0 2 0
173545560 0 0 0 0 0 0 1 0 1
236545965 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 2 0 104167147
1 0 94723253 1 0 0 0 0 0 0
0 1 0 0 0 474995039 0 0 0 1
0 0 0 1 0 0 0 ...

output:

8
969002517 1
1 0
1 1
1 0
1 1
1 1
1 1
1 1
8
902830655 3
1 3
1 3
1 3
1 6
1 3
1 3
1 6
8
216346908 6
1 8
1 6
1 4
1 6
1 6
1 6
1 6
8
365035916 0
1 0
1 0
1 0
1 0
1 0
1 9
1 8
8
447294074 3
1 8
1 3
1 3
1 3
1 3
1 3
1 8
-1
8
236545960 0
1 0
1 0
1 0
1 0
1 0
1 1
1 4
8
104167142 9
1 7
1 7
1 9
1 9
1 9
1 9
1 9
8
9...

result:

ok T=100000

Test #15:

score: 0
Accepted
time: 160ms
memory: 11420kb

input:

100000
311478020 904726460 0 0 0 0 0 0 0 0
0 793041969 693575215 0 0 0 0 0 0 0
0 941737673 0 0 0 0 0 0 128543983 0
374609698 0 0 0 82357820 0 0 0 0 0
184062618 0 0 0 0 118822886 0 0 0 0
447628754 0 0 0 0 0 0 0 0 0
0 0 0 0 395001081 0 0 0 483827406 0
0 0 0 154010312 172784409 0 0 0 0 0
247587485 0 0 ...

output:

12
904726455 1
311478015 0
1 0
1 0
1 0
1 0
1 1
1 0
1 1
1 1
1 1
1 1
12
693575210 2
793041964 1
1 1
1 1
1 1
1 1
1 2
1 2
1 1
1 2
1 2
1 2
7
128543983 8
941737668 1
1 1
1 1
1 1
1 1
1 1
12
82357815 4
374609693 0
1 0
1 0
1 0
1 0
1 4
1 4
1 4
1 4
1 4
1 0
12
118822881 5
184062613 0
1 0
1 0
1 0
1 0
1 5
1 5
1 5...

result:

ok T=100000

Test #16:

score: 0
Accepted
time: 134ms
memory: 11392kb

input:

100000
0 1 0 440498132 475368075 0 0 0 0 0
288355410 611487928 1 0 0 0 0 0 0 0
263421914 0 1 0 0 0 0 0 0 978202847
580168824 0 0 0 0 0 227097610 1 0 0
0 0 1 0 0 0 260392256 0 0 301522084
0 0 0 0 0 0 0 18629803 0 779668569
119647696 0 0 0 1 792598128 0 0 0 0
0 0 0 13823891 0 0 466308612 1 0 0
0 12790...

output:

13
475368070 4
440498127 3
1 1
1 3
1 3
1 3
1 3
1 4
1 4
1 4
1 3
1 4
1 4
13
611487923 1
288355405 0
1 0
1 0
1 0
1 0
1 0
1 2
1 1
1 1
1 1
1 1
1 1
12
978202843 9
263421909 0
1 0
1 0
1 0
1 0
1 9
1 9
1 9
1 9
1 0
1 2
13
227097605 6
1 7
580168819 0
1 0
1 0
1 0
1 0
1 6
1 6
1 6
1 0
1 6
1 6
12
260392251 6
30152...

result:

ok T=100000

Test #17:

score: 0
Accepted
time: 136ms
memory: 11460kb

input:

100000
1 0 1 665089540 0 0 0 400911568 0 0
0 1 901713946 0 424657419 1 0 0 0 0
846736084 0 1 1 0 0 818156688 0 0 0
816527475 0 0 0 832798747 1 0 0 0 0
872170099 916780987 1 0 0 0 1 0 0 0
0 656299015 0 0 0 0 719473525 0 0 0
0 0 0 0 0 365480922 0 981383930 1 0
1 474342127 0 978193314 0 0 0 0 1 0
0 0 0...

output:

13
665089535 3
400911564 7
1 7
1 7
1 7
1 7
1 0
1 3
1 3
1 3
1 2
1 3
1 3
14
424657414 4
901713941 2
1 1
1 2
1 2
1 2
1 2
1 2
1 4
1 4
1 5
1 4
1 4
1 4
14
818156683 6
846736079 0
1 0
1 0
1 0
1 0
1 0
1 2
1 6
1 6
1 3
1 6
1 6
1 6
13
832798742 4
816527470 0
1 0
1 0
1 0
1 0
1 0
1 4
1 4
1 4
1 5
1 4
1 4
14
91678...

result:

ok T=100000