結果

問題 No.3316 Make 81181819 with only 0,1,or 8
コンテスト
ユーザー kmjp
提出日時 2025-10-31 23:17:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 6,000 ms
コード長 1,855 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 199,072 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-31 23:18:02
合計ジャッジ時間 3,319 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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 T,N;


ll p10[13];

pair<int,int> from[12][10];
int num[12][10];
int cand[100];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(x,100) cand[x]=1010;
	
	FOR(x,10) FOR(y,10) if(x+y<10&&x*8+y<100) {
		cand[x*8+y]=min(cand[x*8+y],x+y);
	}
	
	p10[0]=1;
	FOR(i,12) p10[i+1]=p10[i]*10;
	cin>>T;
	while(T--) {
		cin>>N;
		N=81181819-N;
		MINUS(from);
		FOR(x,11) FOR(y,10) num[x][y]=100;
		num[0][0]=from[0][0].first=0;
		FOR(i,10) {
			ll lef=N/p10[i];
			FOR(j,10) if(from[i][j].first!=-1) {
				FOR(x,100) if(cand[x]<10) {
					y=x+j;
					if(y>lef||y>=100) continue;
					if(y%10!=lef%10) continue;
					int ca=y/10;
					if(num[i+1][ca]>max(num[i][j],cand[x])) {
						num[i+1][ca]=max(num[i][j],cand[x]);
						from[i+1][ca]={x,j};
					}
				}
			}
		}
		ll ret[10]={};
		x=num[10][0];
		int ca=0;
		for(i=10;i>=1;i--) {
			int num=from[i][ca].first;
			ca=from[i][ca].second;
			FOR(j,10) {
				if(num>=8) ret[j]+=p10[i-1]*8, num-=8;
				else if(num) ret[j]+=p10[i-1], num-=1;
			}
		}
		
		cout<<x<<endl;
		FOR(i,x) cout<<ret[i]<<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