Submission #249536

# Submission time Handle Problem Language Result Execution time Memory
249536 2020-07-15T08:34:45 Z VEGAnn Klavir (COCI17_klavir) C++14
96 / 160
1000 ms 6632 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("fast-math")
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int M = 1000100;
const int md = int(1e9) + 7;
int a[M], n, m, ans[M];

int mult(int x, int y) { return (1ll * x * y) % md; }

int sum(int x, int y){
    x += y;
    if (x >= md)
        x -= md;
    return x;
}

int sub(int x, int y){
    x -= y;
    if (x < 0)
        x += md;
    return x;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m;

    for (int i = 1; i <= m; i++)
        cin >> a[i];

    ans[0] = 0;

    for (int i = 1; i <= m; i++){
        ans[i] = 0;

        for (int j = 1; j <= n; j++)
            if (a[i] != j){
                int mx = 0;

                for (int len = i - 1; len > 0; len--){
                    if (a[len] != j) continue;

                    bool ok = 1;

                    for (int it = 1; it < len && ok; it++)
                        ok &= bool(a[i - it] == a[len - it]);

                    if (ok){
                        mx = len;
                        break;
                    }
                }

                ans[i] = sum(ans[i], ans[i - 1]);
                ans[i] = sub(ans[i], ans[mx]);
                ans[i] = sum(ans[i], 1);
            } else {
                ans[i] = sum(ans[i], ans[i - 1] + 1);
            }

        cout << ans[i] << " ";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 1340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 6520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 6632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 6536 KB Time limit exceeded
2 Halted 0 ms 0 KB -