Submission #258076

# Submission time Handle Problem Language Result Execution time Memory
258076 2020-08-05T10:03:16 Z tqbfjotld Lucky Numbers (RMI19_lucky) C++14
46 / 100
200 ms 4600 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007LL

int n,q;
int arr[100005];
int memo[100005];

int func(int a){
    if (memo[a]!=-1) return memo[a];
    if (a==0) return memo[0] = 0;
    if (a==1) return memo[1] = 1;
    return memo[a] = (10*func(a-1)-func(a-2)+MOD)%MOD;
}

 main(){
    scanf("%lld%lld",&n,&q);
    for (int x = 0; x<n; x++){
        char c;
        scanf(" %c",&c);
        arr[x] = c-'0';
    }
    memset(memo,-1,sizeof(memo));
    func(n+1);
    int ans = 1;
    for (int x = n-1;x>=0; x--){
        if (arr[x]==0){
            continue;
        }
        if (arr[x]==1) ans += memo[n-1-x]+MOD;
        if (arr[x]==3 && x!=0 && arr[x-1]==1){
            ans = 0;
        }
        if (arr[x]>3 && x!=0 && arr[x-1]==1) ans -= memo[n-x];
        //printf("ans += %lld * %lld - %lld\n",arr[x],memo[n-x],memo[n-1-x]);
        ans += arr[x]*memo[n-x]-memo[n-1-x]+MOD;
        ans %= MOD;
    }
    printf("%lld\n",(ans+MOD)%MOD);
    while (q--){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        if (a==2){
            arr[b-1] = c;
        }
        else{
            int ans = 1;
            for (int x = c-1; x>=b-1; x--){
                if (arr[x] == 0) continue;
                if (arr[x]==1) ans += memo[c-1-x]+MOD;
                if (arr[x]==3 && x!=b-1 && arr[x-1]==1){
                    ans = 0;
                }
                if (arr[x]>3 && x!=b-1 && arr[x-1]==1) ans -= memo[c-x];
                ans += arr[x]*memo[c-x]-memo[c-1-x]+MOD;
                ans %=MOD;
            }
            printf("%lld\n",(ans+MOD)%MOD);
        }
    }
}

Compilation message

lucky.cpp:17:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  main(){
       ^
lucky.cpp: In function 'int main()':
lucky.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&q);
     ~~~~~^~~~~~~~~~~~~~~~~~
lucky.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c",&c);
         ~~~~~^~~~~~~~~~
lucky.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 1528 KB Output is correct
2 Correct 196 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 1528 KB Output is correct
2 Correct 196 ms 1664 KB Output is correct
3 Execution timed out 1081 ms 4600 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 122 ms 1528 KB Output is correct
8 Correct 196 ms 1664 KB Output is correct
9 Correct 62 ms 1536 KB Output is correct
10 Correct 103 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 122 ms 1528 KB Output is correct
8 Correct 196 ms 1664 KB Output is correct
9 Execution timed out 1081 ms 4600 KB Time limit exceeded
10 Halted 0 ms 0 KB -