結果

問題 No.2437 Fragile Multiples of 11
ユーザー 👑 kmjpkmjp
提出日時 2023-08-23 01:11:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,250 ms / 2,000 ms
コード長 1,499 bytes
コンパイル時間 2,082 ms
コンパイル使用メモリ 200,808 KB
実行使用メモリ 75,472 KB
最終ジャッジ日時 2023-08-23 01:12:26
合計ジャッジ時間 24,048 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
75,152 KB
testcase_01 AC 21 ms
75,148 KB
testcase_02 AC 80 ms
75,472 KB
testcase_03 AC 1,250 ms
75,156 KB
testcase_04 AC 1,187 ms
75,156 KB
testcase_05 AC 1,204 ms
75,212 KB
testcase_06 AC 1,208 ms
75,184 KB
testcase_07 AC 1,206 ms
75,204 KB
testcase_08 AC 1,207 ms
75,152 KB
testcase_09 AC 1,194 ms
75,156 KB
testcase_10 AC 1,201 ms
75,168 KB
testcase_11 AC 1,199 ms
75,224 KB
testcase_12 AC 1,198 ms
75,156 KB
testcase_13 AC 1,197 ms
75,156 KB
testcase_14 AC 1,195 ms
75,220 KB
testcase_15 AC 21 ms
75,164 KB
testcase_16 AC 21 ms
75,192 KB
testcase_17 AC 21 ms
75,212 KB
testcase_18 AC 21 ms
75,152 KB
testcase_19 AC 21 ms
75,208 KB
testcase_20 AC 21 ms
75,144 KB
testcase_21 AC 21 ms
75,152 KB
testcase_22 AC 21 ms
75,244 KB
testcase_23 AC 21 ms
75,184 KB
testcase_24 AC 216 ms
75,380 KB
testcase_25 AC 84 ms
75,208 KB
testcase_26 AC 72 ms
75,228 KB
testcase_27 AC 205 ms
75,180 KB
testcase_28 AC 1,147 ms
75,180 KB
testcase_29 AC 992 ms
75,308 KB
testcase_30 AC 1,003 ms
75,216 KB
testcase_31 AC 879 ms
75,212 KB
testcase_32 AC 714 ms
75,180 KB
testcase_33 AC 206 ms
75,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
string X;
ll memo[102][2][2][11][1<<11];
const ll mo=998244353;

ll hoge(int d,int lz,int le,int cmo,int mask) {
	if(d==N) {
		if(lz) return 0;
		if(cmo) return 0;
		if(mask&1) return 0;
		return 1;
	}
	if(memo[d][lz][le][cmo][mask]>=0) return memo[d][lz][le][cmo][mask];
	ll ret=0;
	int i,j;
	FOR(i,10) {
		if(le==0&&i>X[d]) continue;
		int nmo=(cmo*10+i)%11;
		int nmask=1<<cmo;
		FOR(j,11) if(mask&(1<<j)) nmask|=1<<((j*10+i)%11);
		if(lz&&(i==0)) nmask=0;
		ret+=hoge(d+1,lz&&(i==0),le|(i<X[d]),nmo,nmask);
	}
	
	return memo[d][lz][le][cmo][mask]=ret%mo;
	
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>X;
	FORR(x,X) x-='0';
	MINUS(memo);
	
	cout<<hoge(0,1,0,0,0)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0