AtCoderの問題を解くべくC++の次のコードを動かすとSegmentation Faultが出るのですが、原因が分かりません。
C++
1#include <bits/stdc++.h> 2 3const long long mo=1000000000+7; 4 5std::string K; 6int D; 7long long dp[2][50][10001];//1:strict 8 9int main(){ 10 std::cin>>K; 11 std::cin>>D; 12 dp[1][0][0]=1; 13 for(int i=0;i<(int)(K.length());++i){ 14 for(int k=0;k<50;++k){ 15 for(int j=0;j<=9;++j){ 16 int nk=(j+k)%D; 17 dp[0][nk][i+1]+=dp[0][k][i]; 18 dp[0][nk][i+1]%=mo; 19 } 20 for(int j=0;j<(int)(K[i]-'0');++j){ 21 int nk=(j+k)%D; 22 dp[0][nk][i+1]+=dp[1][k][i]; 23 dp[0][nk][i+1]%=mo; 24 } 25 int nk=(k+(int)(K[i]-'0'))%D; 26 dp[1][nk][i+1]+=dp[1][k][i]; 27 dp[1][nk][i+1]%=mo; 28 } 29 } 30 std::cout<<(dp[0][0][(int)(K.length())]+dp[1][0][(int)(K.length())]-1)%mo<<std::endl; 31 return 0; 32}
入力は
98765432109876543210 58
です。
gdbでデバッグしてみたのですが、何も情報は得られませんでした。
gdb ./a.out GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from a.out...(no debugging symbols found)...done. (gdb) run Starting program: a.out warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000 98765432109876543210 58 Program received signal SIGSEGV, Segmentation fault. 0x0000000000400df2 in main () (gdb) quit A debugging session is active. Inferior 1 [process 11348] will be killed. Quit anyway? (y or n) y
原因の分かる方ご教示ください。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/14 02:43