QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#867674#8889. Ice Cream MachinesKK1729#41 1ms3840kbC++171.7kb2025-01-23 21:13:182025-01-23 21:13:18

Judging History

This is the latest submission verdict.

  • [2025-01-23 21:13:18]
  • Judged
  • Verdict: 41
  • Time: 1ms
  • Memory: 3840kb
  • [2025-01-23 21:13:18]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"

void printVector(vector<int> a){
    for (auto x: a) cout << x << " ";
    cout << endl;
}

void solve(){
    int n, m, k; cin >> n >> m >> k;
    vector<int> c(n);
    FOR(i,0,n) cin >> c[i];

    int ans = 0;
    vector<vector<int>> e(m+1);
    FOR(i,0,n) e[c[i]].pb(i);
    vector<int> nex(n, 1e9);
    FOR(i,1,m+1){
        FOR(j,0,e[i].size()-1) nex[e[i][j]] = e[i][j+1];
    }
    vector<int> machine(k, -1);
    vector<int> active(m+1);
    vector<int> curr(m+1);
    FOR(i,0,n){
        // cout << i << ans << endl;
        if (active[c[i]]){
            curr[c[i]] = nex[i];
            continue;
        }
        ans++;
        int t = 0; int l = 0;
        bool done = false;
        FOR(j,0,k){
            if (machine[j] == -1){
                machine[j] = c[i];
                curr[c[i]] = nex[i];
                active[c[i]] = 1;
                done = true;
                break;
            }else{
                if (curr[machine[j]] > l){
                    l = max(l, curr[machine[j]]);
                    t = j;
                }
            }

        }
        if (done) continue;
        active[machine[t]] = 0;
        machine[t] = c[i];
        active[c[i]] = 1;
        curr[c[i]] = nex[i];
    }
    cout << ans << endl;
}


int32_t main(){
    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int t = 1; // cin >> t;
    while (t--) solve();
}

詳細信息

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 1ms
memory: 3840kb

input:

1000 10 1
3
6
6
8
4
7
4
10
1
6
6
2
1
8
4
10
5
9
3
4
7
5
9
6
2
8
8
7
1
1
1
9
8
6
4
6
5
4
8
8
2
3
1
7
7
10
4
10
5
5
2
7
5
1
6
8
7
9
10
4
9
2
4
5
7
8
10
9
1
5
1
7
10
4
10
10
5
10
10
10
5
3
5
5
7
4
6
6
10
6
9
5
6
3
3
3
7
10
7
4
5
10
6
4
2
4
8
7
6
9
7
5
6
9
9
7
4
5
8
8
10
6
1
4
9
3
9
10
1
7
3
4
8
1
3
9
5...

output:

899

result:

ok 1 number(s): "899"

Test #2:

score: 7
Accepted
time: 1ms
memory: 3584kb

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:

1

result:

ok 1 number(s): "1"

Test #3:

score: 7
Accepted
time: 0ms
memory: 3712kb

input:

751 8 1
8
6
5
4
7
8
2
6
4
7
4
2
2
5
3
7
7
3
7
2
5
3
4
8
6
8
1
4
3
8
4
1
3
3
5
3
6
6
8
8
1
4
6
8
8
3
5
7
5
7
1
1
1
2
8
1
8
6
4
5
1
2
7
5
5
5
7
4
3
1
4
3
8
6
5
3
1
7
5
7
8
3
8
2
6
8
6
5
4
1
1
5
1
4
7
7
5
2
6
8
4
3
2
6
5
7
7
4
4
5
1
7
2
2
2
6
7
6
2
4
7
3
2
6
2
3
2
1
4
8
8
7
6
3
4
7
2
4
3
1
7
2
7
1
3
6
...

output:

655

result:

ok 1 number(s): "655"

Test #4:

score: 7
Accepted
time: 0ms
memory: 3840kb

input:

857 3 1
1
3
1
3
2
1
1
2
2
2
1
3
3
3
2
2
3
1
3
1
1
3
1
3
3
2
1
3
1
3
1
1
3
2
2
1
1
3
1
1
2
3
1
1
2
1
3
3
3
3
3
1
1
2
2
3
1
1
2
2
2
3
2
1
2
2
2
3
2
1
3
3
2
2
1
2
3
1
1
1
3
2
3
3
3
1
3
2
2
2
1
3
3
3
2
2
3
1
1
1
1
3
1
3
3
3
1
2
1
3
1
3
2
3
3
3
1
1
1
3
1
3
3
2
2
1
3
3
1
1
3
1
2
1
1
1
2
1
2
2
3
2
2
2
2
3
...

output:

565

result:

ok 1 number(s): "565"

Test #5:

score: 7
Accepted
time: 1ms
memory: 3840kb

input:

888 3 1
2
1
1
3
2
3
2
2
2
1
2
2
1
3
2
1
1
1
2
3
3
1
2
3
1
3
3
3
2
2
1
2
2
1
1
1
2
2
1
3
1
3
3
3
3
2
2
1
3
3
1
1
1
3
3
2
1
2
3
3
2
2
1
3
3
2
1
1
1
1
1
2
2
2
2
3
3
2
1
1
2
3
2
2
1
3
3
1
2
1
2
1
1
2
1
2
1
3
2
2
3
1
3
3
1
1
1
3
1
2
3
2
1
1
1
2
3
2
2
1
2
1
3
3
3
2
3
1
2
2
3
1
1
3
3
3
2
3
2
1
1
3
1
2
3
1
...

output:

599

result:

ok 1 number(s): "599"

Test #6:

score: 7
Accepted
time: 0ms
memory: 3840kb

input:

998 4 1
2
4
1
1
3
4
3
3
2
2
1
2
3
3
4
4
3
3
1
1
1
4
2
1
2
2
2
2
3
2
2
1
2
2
4
3
3
3
3
2
2
3
3
2
3
4
3
4
3
2
4
2
1
2
3
3
2
3
2
4
1
4
1
4
1
4
1
2
3
1
4
3
1
2
2
3
3
2
1
3
3
3
4
2
1
3
2
3
3
4
3
4
1
4
3
4
3
3
1
4
2
3
2
1
4
2
1
1
4
3
4
2
4
4
3
4
4
1
3
4
4
1
2
3
2
1
1
3
3
1
3
3
4
3
1
3
2
4
1
4
4
2
4
2
2
4
...

output:

731

result:

ok 1 number(s): "731"

Test #7:

score: 7
Accepted
time: 0ms
memory: 3584kb

input:

1000 10 1
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9...

output:

1000

result:

ok 1 number(s): "1000"

Subtask #2:

score: 12
Accepted

Dependency #1:

100%
Accepted

Test #8:

score: 12
Accepted
time: 1ms
memory: 3584kb

input:

1000 10 2
5
1
5
10
1
10
9
10
3
9
7
6
4
3
1
10
7
9
5
9
5
4
2
7
7
8
4
4
4
3
10
8
4
2
5
7
5
10
9
2
6
1
4
7
9
5
6
3
4
3
5
4
3
9
2
6
3
2
6
9
8
4
5
5
2
9
10
2
6
1
7
3
6
6
7
4
10
7
8
5
8
8
2
7
8
10
5
2
8
4
2
10
3
9
7
8
6
7
9
7
9
2
5
4
5
10
2
4
3
9
2
3
7
9
3
10
8
4
1
8
9
10
8
10
2
6
3
2
2
5
5
2
8
7
9
5
7
7
...

output:

629

result:

ok 1 number(s): "629"

Test #9:

score: 12
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #10:

score: 12
Accepted
time: 0ms
memory: 3712kb

input:

933 8 2
6
1
4
2
6
3
6
6
8
5
8
6
1
8
5
4
8
2
8
1
8
2
2
4
2
1
1
5
7
1
8
6
1
3
6
6
7
5
3
6
5
6
6
5
5
1
3
7
2
5
7
1
8
7
5
2
8
3
5
6
3
8
8
7
6
4
3
8
8
1
7
6
1
6
2
6
3
4
3
3
4
2
8
5
4
8
1
2
6
4
1
3
2
8
2
4
6
2
8
8
7
6
7
2
6
8
4
2
6
6
5
1
8
2
4
7
3
8
3
6
5
7
4
2
1
4
7
2
8
1
5
5
5
7
6
7
2
3
5
6
4
5
8
7
4
7
...

output:

556

result:

ok 1 number(s): "556"

Test #11:

score: 12
Accepted
time: 0ms
memory: 3712kb

input:

62 6 2
1
3
1
5
6
4
4
1
4
2
4
2
2
4
1
2
1
6
2
5
6
5
2
2
6
6
4
3
6
3
6
6
5
1
5
1
1
3
4
6
4
3
6
3
5
6
5
2
5
5
1
6
1
1
3
3
6
3
4
3
6
3

output:

25

result:

ok 1 number(s): "25"

Test #12:

score: 12
Accepted
time: 0ms
memory: 3712kb

input:

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

output:

374

result:

ok 1 number(s): "374"

Test #13:

score: 12
Accepted
time: 0ms
memory: 3840kb

input:

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

output:

472

result:

ok 1 number(s): "472"

Test #14:

score: 12
Accepted
time: 0ms
memory: 3712kb

input:

1000 10 2
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9...

output:

890

result:

ok 1 number(s): "890"

Subtask #3:

score: 22
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #15:

score: 22
Accepted
time: 0ms
memory: 3840kb

input:

1000 10 5
10
4
1
7
3
7
4
9
7
5
3
7
2
1
2
8
9
10
5
9
8
10
4
7
7
7
9
2
3
4
6
7
9
4
9
4
1
1
8
3
9
3
2
6
4
5
2
3
9
6
9
3
5
9
6
4
7
7
2
5
7
9
6
8
7
10
7
6
10
7
5
10
2
8
10
10
5
3
2
5
10
1
4
5
3
4
7
10
8
8
9
5
2
8
2
2
1
7
4
7
6
1
2
4
10
5
2
5
5
4
9
10
3
3
8
9
5
7
5
10
1
2
4
1
6
6
2
1
8
7
8
3
10
1
1
6
8
10...

output:

284

result:

ok 1 number(s): "284"

Test #16:

score: 22
Accepted
time: 0ms
memory: 3712kb

input:

1000 5 5
1
3
1
1
1
4
3
5
5
3
3
5
1
2
5
4
5
3
1
1
2
3
5
1
3
5
3
3
5
5
5
3
4
3
2
1
1
3
3
3
1
3
3
5
5
4
3
4
3
5
2
1
3
3
1
1
3
1
1
5
1
2
1
4
4
2
5
1
2
4
1
5
4
2
4
4
3
5
2
5
5
3
3
3
4
2
4
3
4
3
3
2
3
2
2
4
1
1
1
2
1
5
2
1
3
3
4
1
2
5
2
4
3
1
2
4
4
1
1
3
3
2
5
5
5
4
1
5
5
1
1
5
5
5
5
5
2
3
3
4
4
5
2
3
2
3...

output:

5

result:

ok 1 number(s): "5"

Test #17:

score: 22
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

269

result:

ok 1 number(s): "269"

Test #18:

score: 22
Accepted
time: 0ms
memory: 3712kb

input:

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

output:

64

result:

ok 1 number(s): "64"

Test #19:

score: 22
Accepted
time: 0ms
memory: 3712kb

input:

881 5 3
4
2
5
1
3
2
1
5
3
2
4
2
3
4
3
5
1
2
2
4
2
1
5
4
5
3
2
4
2
2
2
4
2
5
3
4
5
4
2
5
2
2
4
4
4
5
1
4
5
5
4
2
2
2
2
1
5
1
2
2
4
1
4
5
5
2
4
2
4
4
3
2
4
5
1
2
1
2
2
5
2
1
1
4
3
3
5
1
3
4
1
2
4
5
2
2
2
3
2
3
3
2
5
4
4
3
2
4
4
3
4
3
2
1
2
5
1
1
3
3
1
4
3
1
2
5
5
4
2
1
1
5
2
2
4
5
1
3
1
1
2
1
4
5
2
3
...

output:

222

result:

ok 1 number(s): "222"

Test #20:

score: 22
Accepted
time: 0ms
memory: 3712kb

input:

395 8 3
4
5
6
5
7
3
3
2
4
2
3
6
5
2
7
1
2
3
4
1
5
8
5
8
5
4
5
1
5
5
3
4
6
4
7
2
4
5
4
1
4
8
3
2
5
7
4
3
3
1
7
8
1
3
2
3
7
7
4
5
2
4
1
1
1
3
2
1
7
1
1
2
6
1
2
5
4
8
8
4
6
4
6
1
5
2
4
5
8
5
8
4
2
7
5
6
2
2
3
5
4
3
3
7
1
5
4
8
4
2
4
5
3
3
4
6
1
7
8
1
5
1
6
6
1
3
4
3
2
6
8
7
6
2
8
8
1
2
3
8
5
4
1
8
5
4
...

output:

169

result:

ok 1 number(s): "169"

Test #21:

score: 22
Accepted
time: 0ms
memory: 3584kb

input:

1000 5 5
1
2
3
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5...

output:

5

result:

ok 1 number(s): "5"

Test #22:

score: 22
Accepted
time: 1ms
memory: 3712kb

input:

1000 2 2
1
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:

2

result:

ok 1 number(s): "2"

Test #23:

score: 22
Accepted
time: 1ms
memory: 3712kb

input:

1000 10 5
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9...

output:

560

result:

ok 1 number(s): "560"

Subtask #4:

score: 0
Runtime Error

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #24:

score: 0
Runtime Error

input:

1000 200 100
125
25
197
45
187
19
77
114
143
176
87
180
3
10
92
95
22
170
50
133
76
157
200
144
73
185
127
140
133
29
40
39
54
166
56
76
151
200
188
9
60
199
112
28
188
87
68
100
74
85
60
68
187
5
105
1
35
198
150
150
24
148
14
40
159
173
25
181
176
88
138
42
78
51
130
190
180
19
127
98
28
172
135
1...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

0%