QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#333510#5589. Everything Is A Nailhxd248AC ✓111ms56376kbC++141.2kb2024-02-20 03:23:512024-02-20 03:23:51

Judging History

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

  • [2024-02-20 03:23:51]
  • 评测
  • 测评结果:AC
  • 用时:111ms
  • 内存:56376kb
  • [2024-02-20 03:23:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int t;
int tasks[300300];
int dp[300300][3][8];
int solve(int i, int tool, int used) 
{
    //i表示位置,tool表示当前使用工具,used表示可使用的工具状态(000,001,...,111)
    if (i < 0) return 0;
    int &x = dp[i][tool][used];
    if (x == -1)
        if (tool == tasks[i]) //如果当前工具与任务类型一致,则上一个工具状态与当前相同
                              //说明上一个也是使用当前工具且并未发生切换
            x = max(x, solve(i-1, tool, used)+1);
        else 				//如果当前工具与任务类型不一致,则有可能由上一个工具处理
                            //完当前任务后切换成tool,或者上一次也是tool,只不过不处理
                            //当前任务
            for (int j = 0; j < 3; j++)
                if (~used>>j&1 || j==tool)
                    x = max(x, solve(i-1, j, used|(1<<j)) + (tasks[i] == j));
    return x;
}
int main() 
{
    cin >> t;
    for (int i = 0; i < t; i++)
        cin >> tasks[i];
    memset(dp, -1, sizeof dp);
    cout << max(solve(t-1, 0, 1), max(solve(t-1, 1, 2), solve(t-1, 2, 4))) << endl;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 31836kb

input:

10
1
1
1
0
0
0
0
2
2
2

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 0ms
memory: 31752kb

input:

10
0
1
2
0
1
2
0
1
2
0

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 3ms
memory: 31716kb

input:

1
0

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 31712kb

input:

1
1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 31752kb

input:

1
2

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 31744kb

input:

10
0
0
0
0
0
0
0
0
0
0

output:

10

result:

ok single line: '10'

Test #7:

score: 0
Accepted
time: 0ms
memory: 31772kb

input:

10
1
2
0
1
2
0
1
2
0
1

output:

5

result:

ok single line: '5'

Test #8:

score: 0
Accepted
time: 4ms
memory: 31712kb

input:

10
0
0
0
0
0
2
2
2
1
1

output:

10

result:

ok single line: '10'

Test #9:

score: 0
Accepted
time: 3ms
memory: 31708kb

input:

10
0
2
1
0
0
1
1
0
0
2

output:

6

result:

ok single line: '6'

Test #10:

score: 0
Accepted
time: 0ms
memory: 31680kb

input:

10
0
1
2
2
0
0
1
1
2
1

output:

7

result:

ok single line: '7'

Test #11:

score: 0
Accepted
time: 0ms
memory: 31840kb

input:

10
2
1
1
2
1
1
2
2
0
0

output:

8

result:

ok single line: '8'

Test #12:

score: 0
Accepted
time: 3ms
memory: 31768kb

input:

1000
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...

output:

1000

result:

ok single line: '1000'

Test #13:

score: 0
Accepted
time: 0ms
memory: 31788kb

input:

1000
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2...

output:

335

result:

ok single line: '335'

Test #14:

score: 0
Accepted
time: 3ms
memory: 31840kb

input:

1000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1...

output:

1000

result:

ok single line: '1000'

Test #15:

score: 0
Accepted
time: 0ms
memory: 31848kb

input:

1000
0
0
0
2
1
1
1
1
0
1
2
2
0
2
0
0
1
2
0
1
2
0
2
2
1
2
0
1
2
0
2
0
2
1
2
1
2
1
2
2
1
2
2
2
0
2
0
1
2
0
2
1
2
0
2
1
0
1
2
0
0
2
0
0
1
0
0
0
0
1
0
1
2
1
2
2
1
2
0
1
1
1
2
1
2
1
1
0
0
0
1
1
0
0
0
0
2
0
0
1
0
1
0
2
0
0
2
0
2
1
1
0
0
2
1
1
0
1
2
0
2
2
2
0
0
1
2
1
1
0
1
1
2
1
2
1
0
1
0
2
1
0
1
1
1
0
2
2...

output:

372

result:

ok single line: '372'

Test #16:

score: 0
Accepted
time: 0ms
memory: 31848kb

input:

1000
2
0
0
2
1
0
0
0
0
1
0
0
1
1
2
1
2
0
0
2
0
1
1
0
1
2
0
1
1
1
0
1
1
1
1
2
0
1
2
0
1
1
2
1
2
1
1
1
1
1
2
2
2
0
2
1
2
2
0
2
2
1
2
1
1
0
1
2
1
2
2
2
2
2
0
0
1
2
1
0
0
0
1
0
2
0
2
2
1
0
1
0
1
0
1
1
1
0
2
2
0
0
2
1
2
1
2
1
1
0
0
0
0
2
1
0
2
0
2
0
1
1
1
1
2
1
2
1
1
1
1
0
0
0
0
2
2
0
1
0
2
2
1
0
0
2
1
1...

output:

382

result:

ok single line: '382'

Test #17:

score: 0
Accepted
time: 0ms
memory: 31792kb

input:

1000
0
2
2
2
2
1
0
2
2
1
1
2
1
1
1
1
2
0
0
2
2
2
2
1
1
1
0
0
0
1
2
0
2
2
0
2
2
0
1
2
0
2
1
2
2
1
1
2
2
2
0
2
2
2
1
0
2
0
0
0
1
0
0
0
0
2
2
2
0
2
2
2
0
2
2
0
0
2
1
0
2
1
0
0
0
0
0
1
2
2
1
0
2
2
1
2
2
1
0
1
0
1
1
1
1
1
2
2
0
1
1
1
2
2
0
1
2
1
1
1
0
0
0
1
0
1
0
0
2
0
2
1
0
2
2
2
0
1
0
0
2
1
0
1
1
1
0
2...

output:

373

result:

ok single line: '373'

Test #18:

score: 0
Accepted
time: 0ms
memory: 31968kb

input:

2500
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...

output:

2500

result:

ok single line: '2500'

Test #19:

score: 0
Accepted
time: 0ms
memory: 31880kb

input:

2500
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1...

output:

835

result:

ok single line: '835'

Test #20:

score: 0
Accepted
time: 4ms
memory: 31964kb

input:

2500
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2...

output:

2500

result:

ok single line: '2500'

Test #21:

score: 0
Accepted
time: 4ms
memory: 31880kb

input:

2500
1
0
0
1
1
1
1
0
1
0
0
0
2
1
1
1
0
2
1
2
0
2
2
2
0
0
2
2
1
0
1
2
2
1
0
0
1
2
2
2
1
1
1
0
0
0
2
1
2
1
2
2
2
1
1
0
0
0
0
1
0
2
1
2
2
1
1
1
0
0
2
2
1
2
1
0
2
0
2
2
1
0
1
0
2
2
0
2
0
2
2
1
2
2
0
1
2
1
0
1
2
0
2
1
0
0
2
2
1
2
1
0
1
2
1
1
0
1
2
2
1
0
1
0
2
1
2
1
1
0
1
1
2
0
2
1
0
2
0
0
0
2
1
2
0
1
0
2...

output:

889

result:

ok single line: '889'

Test #22:

score: 0
Accepted
time: 3ms
memory: 31964kb

input:

2500
0
2
1
1
2
0
0
1
0
1
1
1
1
2
2
1
2
2
0
0
1
0
0
1
0
2
2
1
0
1
2
0
1
2
0
0
0
2
2
2
0
1
0
0
2
0
1
2
1
1
1
1
0
2
2
1
2
0
2
0
0
0
0
1
1
2
2
2
0
1
2
2
2
0
2
2
2
0
0
0
0
0
1
2
1
1
1
0
0
1
1
2
2
0
2
0
2
0
1
2
2
0
0
1
0
0
2
0
1
2
0
1
2
0
0
0
0
0
0
1
0
2
2
2
1
2
0
2
1
2
1
2
0
0
0
2
0
1
0
1
2
1
1
1
0
2
0
1...

output:

890

result:

ok single line: '890'

Test #23:

score: 0
Accepted
time: 9ms
memory: 32016kb

input:

2500
2
2
2
2
1
2
0
1
0
1
1
1
1
2
1
2
2
1
0
2
1
1
2
1
1
2
2
2
1
1
0
1
0
2
0
2
1
1
0
0
0
2
0
2
2
2
1
2
1
2
2
0
1
1
2
0
2
2
2
2
0
1
2
0
2
0
2
2
1
0
0
2
1
0
0
1
1
0
2
2
2
0
0
0
0
0
0
2
2
1
2
2
0
1
1
2
0
0
0
2
0
1
1
1
0
1
1
0
1
0
2
0
2
1
2
0
2
1
0
1
1
1
1
2
0
1
2
2
1
0
0
0
1
1
1
2
0
2
1
2
1
2
2
0
1
2
0
1...

output:

881

result:

ok single line: '881'

Test #24:

score: 0
Accepted
time: 0ms
memory: 32496kb

input:

10000
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
...

output:

10000

result:

ok single line: '10000'

Test #25:

score: 0
Accepted
time: 8ms
memory: 32580kb

input:

10000
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
...

output:

3335

result:

ok single line: '3335'

Test #26:

score: 0
Accepted
time: 4ms
memory: 32652kb

input:

10000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

10000

result:

ok single line: '10000'

Test #27:

score: 0
Accepted
time: 0ms
memory: 32512kb

input:

10000
2
2
2
1
1
0
0
1
2
1
2
1
2
0
0
1
1
1
1
2
0
2
0
0
2
0
2
2
2
1
2
2
0
1
0
0
2
1
0
0
1
1
2
0
1
0
0
0
1
1
2
2
0
2
1
0
1
2
1
0
1
2
1
2
1
0
1
0
0
0
0
2
2
1
0
1
2
1
1
0
0
0
2
0
2
2
0
0
0
2
1
0
0
2
0
2
2
0
0
0
1
0
0
1
0
1
1
2
1
1
1
2
0
2
1
2
0
2
2
0
2
1
0
0
2
2
1
2
0
1
0
1
2
0
0
2
0
2
0
1
2
2
2
2
0
1
2
...

output:

3470

result:

ok single line: '3470'

Test #28:

score: 0
Accepted
time: 8ms
memory: 32608kb

input:

10000
1
2
1
0
2
0
1
1
0
2
0
2
1
1
1
1
0
2
2
0
0
1
2
2
1
0
2
2
0
1
0
2
0
2
0
0
2
2
1
2
2
0
2
1
0
0
2
1
2
2
0
2
2
1
0
1
1
0
1
0
1
0
1
1
2
1
2
0
2
2
2
0
2
1
1
0
1
1
0
0
1
0
1
2
2
1
0
2
0
1
2
2
0
0
2
1
1
1
2
1
1
0
1
2
0
0
2
1
1
2
0
0
2
0
0
0
1
2
0
1
1
0
1
1
2
2
0
2
1
1
1
0
0
2
2
2
1
1
2
0
2
2
1
2
2
2
0
...

output:

3491

result:

ok single line: '3491'

Test #29:

score: 0
Accepted
time: 4ms
memory: 32632kb

input:

10000
2
0
2
1
1
2
2
0
0
1
2
0
0
1
1
1
1
0
1
0
1
2
0
2
0
0
1
2
1
1
0
1
2
0
1
1
2
2
0
2
1
0
2
2
1
0
2
2
2
1
2
0
2
0
2
0
0
1
0
0
2
1
0
0
1
0
0
2
2
0
0
1
1
2
0
2
0
1
1
1
2
1
0
2
2
1
1
1
1
2
0
0
2
2
0
0
1
0
1
2
2
0
1
0
0
1
0
0
2
2
1
0
1
1
0
2
2
1
0
1
1
2
1
0
0
0
1
1
0
2
1
2
2
1
2
1
0
1
2
1
1
1
2
2
1
0
1
...

output:

3489

result:

ok single line: '3489'

Test #30:

score: 0
Accepted
time: 79ms
memory: 56292kb

input:

300000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1...

output:

300000

result:

ok single line: '300000'

Test #31:

score: 0
Accepted
time: 93ms
memory: 56292kb

input:

300000
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
0...

output:

100002

result:

ok single line: '100002'

Test #32:

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

input:

300000
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2...

output:

300000

result:

ok single line: '300000'

Test #33:

score: 0
Accepted
time: 105ms
memory: 56376kb

input:

300000
2
0
0
1
0
0
0
1
0
1
1
0
2
2
0
1
0
2
2
0
2
0
0
0
1
1
2
0
2
0
1
1
0
2
1
0
0
0
0
1
0
0
0
1
2
2
1
1
1
2
2
1
0
2
2
1
1
2
0
0
0
2
0
0
2
1
0
1
1
1
1
0
2
2
2
1
1
1
2
0
0
2
1
1
0
0
2
1
0
2
1
0
1
0
2
0
2
2
1
0
1
0
0
0
0
0
0
2
0
2
2
0
1
0
1
0
1
1
2
1
2
0
2
1
2
1
0
0
2
2
2
1
1
0
2
1
1
0
1
2
1
0
1
0
0
0
1...

output:

100888

result:

ok single line: '100888'

Test #34:

score: 0
Accepted
time: 111ms
memory: 56280kb

input:

300000
2
1
1
2
2
0
0
0
0
2
1
0
0
1
2
2
1
0
1
1
2
2
0
2
0
0
1
2
2
1
2
0
0
1
0
2
0
0
1
2
0
2
1
1
2
2
0
1
2
2
2
1
0
2
2
2
2
1
0
2
2
2
0
1
1
2
1
0
0
2
0
0
2
2
2
2
0
2
1
1
0
0
1
1
1
1
2
0
1
1
1
1
1
2
1
1
1
0
0
1
0
1
2
1
2
2
2
2
0
0
1
1
1
1
2
2
2
2
1
0
1
0
0
0
2
2
2
1
0
2
0
2
2
0
1
0
1
2
2
0
1
1
2
2
2
2
0...

output:

100714

result:

ok single line: '100714'

Test #35:

score: 0
Accepted
time: 110ms
memory: 56340kb

input:

300000
0
0
1
0
2
1
0
1
2
0
0
2
0
2
2
1
0
0
1
2
0
2
2
2
1
1
1
2
2
1
1
2
2
1
0
2
1
1
2
0
2
2
0
0
2
2
1
2
2
2
0
1
0
1
2
2
0
1
1
1
1
1
1
1
0
0
1
1
2
1
2
1
0
2
2
0
1
2
0
2
0
2
2
1
1
2
0
0
2
1
1
2
1
1
2
0
0
2
1
0
2
0
2
1
0
2
1
1
0
1
0
2
2
2
2
2
2
2
2
1
0
2
2
0
1
0
0
0
1
2
1
1
2
1
1
1
1
2
2
0
1
2
1
2
1
1
1...

output:

100845

result:

ok single line: '100845'