89132024-02-04 14:05:47bovizdbSzínes szobák (50 pont)cpp17Time limit exceeded 11/50400ms8632 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define endl "\n"
#define pll pair<ll, ll>
#define fs first
#define sc second
#define vll vector<ll>
#define v2d vector<vector<ll>>
#define vpll vector<pll>
#define qll queue<ll>
#define stll stack<ll>
#define sll set<ll>
#define mll map<ll, ll>

ll n, k, m;
vll v, v2;
v2d vk;
ll ans;

void solve()
{
    cin >> n >> k >> m;
    v.resize(n, 1);
    vk.resize(k);
    for (ll i = 0; i < n; i++)
    {
        ll in;
        cin >> in;
        vk[in-1].push_back(i);
    }
    for (ll i = 0; i < m; i++)
    {
        ll c, x;
        cin >> c >> x;
        c--;
        v2 = v;
        for (ll j = 0; j < vk[c].size(); j++)
        {
            if (vk[c][j]+x >= n)
            {
               ans += v[n-1];
               v2[n-1] = 0;
            }
            else if (vk[c][j]+x < 0)
            {
                ans += v[0];
                v2[0] = 0;
            }
            else
            {
                v2[vk[c][j]+x] += v[vk[c][j]];
                v2[vk[c][j]] = v2[vk[c][j]]-v[vk[c][j]];
            }
        }
        v = v2;
    }
    cout << ans;
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base11/50
1Accepted0/03ms1928 KiB
2Time limit exceeded0/0400ms6756 KiB
3Wrong answer0/14ms2540 KiB
4Accepted1/14ms2436 KiB
5Wrong answer0/14ms2436 KiB
6Accepted1/14ms2740 KiB
7Accepted1/14ms2692 KiB
8Accepted1/14ms3096 KiB
9Accepted1/14ms3112 KiB
10Accepted1/19ms3380 KiB
11Accepted1/14ms3264 KiB
12Accepted1/19ms3584 KiB
13Wrong answer0/1100ms3916 KiB
14Wrong answer0/135ms4112 KiB
15Wrong answer0/143ms4216 KiB
16Accepted1/1163ms4212 KiB
17Accepted1/1203ms4500 KiB
18Accepted1/1202ms4736 KiB
19Time limit exceeded0/1379ms6236 KiB
20Time limit exceeded0/1368ms6348 KiB
21Time limit exceeded0/1368ms6528 KiB
22Time limit exceeded0/1365ms6404 KiB
23Time limit exceeded0/1377ms6408 KiB
24Time limit exceeded0/1333ms6408 KiB
25Time limit exceeded0/1354ms6408 KiB
26Time limit exceeded0/1372ms6332 KiB
27Time limit exceeded0/3381ms8560 KiB
28Time limit exceeded0/3377ms8440 KiB
29Time limit exceeded0/3368ms8448 KiB
30Time limit exceeded0/3368ms8532 KiB
31Time limit exceeded0/3361ms8632 KiB
32Time limit exceeded0/3370ms8536 KiB
33Time limit exceeded0/4365ms5768 KiB
34Time limit exceeded0/4384ms5760 KiB