# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
477944 | 2021-10-04T17:42:59 Z | stefantaga | Lucky Numbers (RMI19_lucky) | C++14 | 28 ms | 10316 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1000000007; ll mem[100005][2]; int a[100005]; int n,q; ll dp(int id, int lastone){ if (id == 0) return 1; if (mem[id][lastone] != -1) return mem[id][lastone]; ll ret = 0; for (int i = 0; i < 10; i++){ if (lastone && i == 3) continue; ret += dp(id-1,i==1); } ret %= mod; //printf("%d %d %lld\n",id,lastone,ret); return mem[id][lastone] = ret; } ll qu(int l, int r){ ll ret = 0; int ct = r-l; bool isthirteenalready = false; for (int i = l; i <= r && !isthirteenalready; i++, ct--){ int num = a[i]-(i!=l && a[i-1]==1 && a[i]>3); int numone = (a[i]>1); if (numone) ret += dp(ct,1); ret += (num-numone)*dp(ct,0); if (i != l && a[i-1] == 1 && a[i] == 3) isthirteenalready = true; } if (!isthirteenalready) ret++; ret %= mod; return ret; } int main(){ scanf("%d%d",&n,&q); for (int i = 0; i < n; i++){ char ch; scanf(" %c",&ch); a[i] = ch-'0'; } memset(mem,-1,sizeof(mem)); printf("%lld\n",qu(0,n-1)); for (int i = 0; i < q; i++){ int t,l,r; scanf("%d%d%d",&t,&l,&r); if (t == 1){ printf("%lld\n",qu(--l,--r)); } else{ a[--l] = r; } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1740 KB | Output is correct |
2 | Correct | 1 ms | 1868 KB | Output is correct |
3 | Correct | 1 ms | 1868 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1740 KB | Output is correct |
2 | Correct | 1 ms | 1868 KB | Output is correct |
3 | Correct | 1 ms | 1868 KB | Output is correct |
4 | Correct | 1 ms | 1840 KB | Output is correct |
5 | Correct | 1 ms | 1740 KB | Output is correct |
6 | Correct | 1 ms | 1868 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 2684 KB | Output is correct |
2 | Correct | 14 ms | 2892 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 2684 KB | Output is correct |
2 | Correct | 14 ms | 2892 KB | Output is correct |
3 | Correct | 22 ms | 8672 KB | Output is correct |
4 | Correct | 23 ms | 8576 KB | Output is correct |
5 | Correct | 27 ms | 9492 KB | Output is correct |
6 | Correct | 28 ms | 10308 KB | Output is correct |
7 | Correct | 28 ms | 10316 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1740 KB | Output is correct |
2 | Correct | 1 ms | 1868 KB | Output is correct |
3 | Correct | 1 ms | 1868 KB | Output is correct |
4 | Correct | 1 ms | 1840 KB | Output is correct |
5 | Correct | 1 ms | 1740 KB | Output is correct |
6 | Correct | 1 ms | 1868 KB | Output is correct |
7 | Correct | 11 ms | 2684 KB | Output is correct |
8 | Correct | 14 ms | 2892 KB | Output is correct |
9 | Correct | 7 ms | 2636 KB | Output is correct |
10 | Correct | 10 ms | 2848 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1740 KB | Output is correct |
2 | Correct | 1 ms | 1868 KB | Output is correct |
3 | Correct | 1 ms | 1868 KB | Output is correct |
4 | Correct | 1 ms | 1840 KB | Output is correct |
5 | Correct | 1 ms | 1740 KB | Output is correct |
6 | Correct | 1 ms | 1868 KB | Output is correct |
7 | Correct | 11 ms | 2684 KB | Output is correct |
8 | Correct | 14 ms | 2892 KB | Output is correct |
9 | Correct | 22 ms | 8672 KB | Output is correct |
10 | Correct | 23 ms | 8576 KB | Output is correct |
11 | Correct | 27 ms | 9492 KB | Output is correct |
12 | Correct | 28 ms | 10308 KB | Output is correct |
13 | Correct | 28 ms | 10316 KB | Output is correct |
14 | Correct | 7 ms | 2636 KB | Output is correct |
15 | Correct | 10 ms | 2848 KB | Output is correct |
16 | Correct | 19 ms | 8592 KB | Output is correct |
17 | Correct | 19 ms | 8524 KB | Output is correct |
18 | Correct | 20 ms | 9420 KB | Output is correct |
19 | Correct | 22 ms | 10280 KB | Output is correct |
20 | Correct | 26 ms | 10304 KB | Output is correct |