Submission #864367

#TimeUsernameProblemLanguageResultExecution timeMemory
864367AgentPenginLucky Numbers (RMI19_lucky)C++11
0 / 100
0 ms348 KiB
/** * author: AgentPengin ( Độc cô cầu bại ) * created: 23.12.2022 10:08:02 * too lazy to update time **/ #include<bits/stdc++.h> #define EL '\n' #define fi first #define se second #define NAME "NAME" #define ll long long #define lcm(a,b) (a/gcd(a,b))*b #define db(val) "["#val" = " << (val) << "] " #define bend(v) (v).begin(),(v).end() #define sz(v) (int)(v).size() #define ex exit(0) using namespace std; const ll mod = 1e9 + 7; const int inf = 0x1FFFFFFF; const int MAXN = 105; int n,q,a[MAXN],target; ll dp[MAXN][2][2]; ll f(int id,bool lower,bool one) { if (id == (target + 1)) { return 1; } ll &res = dp[id][lower][one]; if (res != -1) return res; res = 0; int up = (lower == true ? 9 : a[id]); for (int dig = 0;dig <= up;dig++) { bool nxt_lower = lower || (dig < a[id]); if (dig == 3 && one) continue; res = (res + f(id + 1,nxt_lower,dig == 1)) % mod; } return res; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); if (ifstream(NAME".inp")) { freopen(NAME".inp","r",stdin); freopen(NAME".out","w",stdout); } cin >> n >> q; for (int i = 1;i <= n;i++) { char c; cin >> c; a[i] = c - '0'; } while(q--) { int type; cin >> type; if (type == 2) { int pos,val; cin >> pos >> val; a[pos] = val; } else { int l,r; cin >> l >> r; target = r; memset(dp,-1,sizeof dp); cout << f(l,0,0) << EL; } } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; } // agent pengin wants to take apio (with anya-san)

Compilation message (stderr)

lucky.cpp: In function 'int main()':
lucky.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
lucky.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen(NAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...