ã主客転åã»å¯ä¸å解ãã®å ¸ååé¡ï¼
åé¡æ¦è¦
1 ãã 9 ã¾ã§ã®æ°åãããªã æ¡ã®æ´æ°å¤ ãä¸ããããã
ãã®æ´æ°å¤ã®é£ç¶ããåºéãåãåºãã¦ã§ããæ´æ°å¤ã®ç·åãæ±ãããï¼998244353 ã§å²ããªããï¼
å¶ç´
èãããã¨
ãã®æã®åé¡ã§ã¯ã ã®åæ¡ã®å¤ã«ã¤ãã¦ãä½å足ãããã®ãããèããã®ãå®ç³ã ããã¨ãã°ã = "4649" ã¨ãã¦ã¿ããããã®ã¨ãã
- æåã® 4 ã¯ã"4", "46", "464", "4649" ã«ã¤ãã¦ããããã 1 åã10 åã100 åã1000 åã«ãã¦è¶³ãããã¨èãã¦ã1111 å
- 次㮠6 ã¯ã"6", "46", "64", "464", "649", "4649" ã«ã¤ãã¦ããããã 1 åã1 åã10 åã10 åã100 åã100 åã«ãã¦è¶³ãããã¨èãã¦ã222 å
- 次㮠4 ã¯ã"4", "64", "464", "49", "649", "4649" ã«ã¤ãã¦ããããã 1 åã1 åã1 åã10 åã10 åã10 åã«ãã¦è¶³ãããã¨èãã¦ã33 å
- 次㮠9 ã¯ã"9", "49", "649", "4649" ã«ã¤ãã¦ããããã 1 åã1 åã1 åã1 åã«ãã¦è¶³ãããã¨èãã¦ã4 å
ã¨ãªãããã£ã¦ãçãã¯
4 Ã 1111 + 6 Ã 222 + 4 Ã 33 + 9 Ã 4
ã¨ãªãããããå°ãæ´çããã¨
(4 Ã 1) Ã 1000
+ (4 Ã 1 + 6 Ã 2) Ã 100
+ (4 Ã 1 + 6 Ã 2 + 4 Ã 3) Ã 10
+ (4 Ã 1 + 6 Ã 2 + 4 Ã 3 + 9 Ã 4) Ã 1
ã¨è¡¨ç¾ã§ãããããã¾ã§åããã°ã容æã«ä¸è¬åã§ããã
å¤åé·æ´æ°ã©ã¤ãã©ãªããªãã¦ã
ä¸è¨ã®çµæã¯ãåé²æ³ã®åæ¡ã®å¤ãæ¦ãæ±ã¾ãå½¢ã«ãªã£ã¦ããã®ã§ãç¹°ãä¸ããããã¡ãã¨èæ ®ãã¦ãããã°ãå¤åé·æ´æ°ã©ã¤ãã©ãªããªãã¦ãè¨ç®ã§ããã
è¨ç®é㯠ã¨è©ä¾¡ã§ããã
ã³ã¼ã
#include <bits/stdc++.h> using namespace std; int main() { long long N; string S; cin >> N >> S; // åæ¡ã®åãæ±ãã¦ãã vector<long long> res; long long sum = 0; for (int i = 0; i < N; i++) { sum += (long long)(S[i] - '0') * (i + 1); res.push_back(sum); } // ç¹°ãä¸ããå å³ããªãã足ãã¦ãã long long kuriagari = 0; for (long long i = N-1; i >= 0; i--) { res[i] += kuriagari; kuriagari = res[i] / 10; res[i] %= 10; } // åºå if (kuriagari) cout << kuriagari; for (auto val : res) cout << val; cout << endl; }