結果

問題 No.372 It's automatic
ユーザー 0w10w1
提出日時 2016-12-21 17:25:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,023 ms / 6,000 ms
コード長 1,582 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 165,036 KB
実行使用メモリ 5,160 KB
最終ジャッジ日時 2023-08-21 04:04:34
合計ジャッジ時間 29,039 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,928 KB
testcase_01 AC 2 ms
4,948 KB
testcase_02 AC 3 ms
5,076 KB
testcase_03 AC 3 ms
4,884 KB
testcase_04 AC 2,000 ms
4,968 KB
testcase_05 AC 2,017 ms
4,900 KB
testcase_06 AC 2,013 ms
4,920 KB
testcase_07 AC 2,015 ms
5,024 KB
testcase_08 AC 2,019 ms
4,956 KB
testcase_09 AC 2,008 ms
4,880 KB
testcase_10 AC 2,005 ms
4,960 KB
testcase_11 AC 1,995 ms
4,976 KB
testcase_12 AC 2,023 ms
4,960 KB
testcase_13 AC 2,002 ms
4,880 KB
testcase_14 AC 2,011 ms
5,016 KB
testcase_15 AC 2,018 ms
5,040 KB
testcase_16 AC 4 ms
4,884 KB
testcase_17 AC 4 ms
5,132 KB
testcase_18 AC 3 ms
4,888 KB
testcase_19 AC 3 ms
4,936 KB
testcase_20 AC 3 ms
4,876 KB
testcase_21 AC 381 ms
4,968 KB
testcase_22 AC 398 ms
4,888 KB
testcase_23 AC 390 ms
4,904 KB
testcase_24 AC 378 ms
4,980 KB
testcase_25 AC 392 ms
5,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;
const int MOD7 = ( int ) 1e9 + 7;

string S;
int M;

void init(){
  cin >> S;
  cin >> M;
}

const int MAXM = ( int ) 2e5;

int dp[ 2 ][ MAXM ]; // rolling, mod M

void preprocess(){

}

void solve(){
  int ans = 0;
  dp[ 0 ][ 0 ] = 0;
  for( int i = 0; i < S.size(); ++i ){
    memset( dp[ ~i & 1 ], 0, sizeof( dp[ ~i & 1 ] ) );
    if( S[ i ] != '0' ){
      ( dp[ ~i & 1 ][ ( S[ i ] - '0' ) % M ] += 1 ) %= MOD7;
      if( ( S[ i ] - '0' ) % M == 0 )
        ( ans += 1 ) %= MOD7;
    } else{
      ( ans += 1 ) %= MOD7;
    }
    for( int j = 0; j < M; ++j ){
      ( dp[ ~i & 1 ][ ( j * 10 + S[ i ] - '0' ) % M ] += dp[ i & 1 ][ j ] ) %= MOD7;
      if( ( j * 10 + S[ i ] - '0' ) % M == 0 ){
        ( ans += dp[ i & 1 ][ j ] ) %= MOD7;
      }
      ( dp[ ~i & 1 ][ j ] += dp[ i & 1 ][ j ] ) %= MOD7;
    }
    // for( int j = 0; j < M; ++j ) cout << dp[ ~i & 1 ][ j ] << endl;
  }
  cout << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0