結果
問題 |
No.3245 Payment with 8-rep Currency
|
ユーザー |
![]() |
提出日時 | 2025-08-28 08:31:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,541 bytes |
コンパイル時間 | 746 ms |
コンパイル使用メモリ | 70,276 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-28 08:31:37 |
合計ジャッジ時間 | 7,036 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include <iostream> #include <cassert> using namespace std; typedef long long ll; struct S { ll a,b,c,d; }; void pri(S s){ cout << s.a << " " << s.b << " " << s.c << " " << s.d << "\n"; } void ch(S s,ll x){ assert(s.a + s.b*11 + s.c*111 + s.d*1111==x); } const int B = 3000; S ans[B + 10]; int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int i,t; cin >> t; for(i=0;i<=B;i++) ans[i] = {-1,-1,-1,-1}; for(int a=0;a*1<=B;a++){ for(int b=0;a + b*11<=B;b++){ for(int c=0;a + b*11 + c*111<=B;c++){ for(int d=0;a + b*11 + c*111 + d*1111<=B;d++){ int sum = a + b + c + d; if(2*a<sum && 2*b<sum && 2*c<sum && 2*d<sum){ ans[a + b*11 + c*111 + d*1111] = {a,b,c,d}; } } } } } while(t){ t--; ll n; cin >> n; if(n%8){ cout << -1 << "\n"; continue; } n /= 8; if(n<=B){ if(ans[n].a==-1) cout << -1 << "\n"; else{ pri(ans[n]); ch(ans[n],n); } }else{ ll x = n; ll a = 0,b = 0,c = 0,d = 0; while(n%3){ d++; n -= 1111; } while(c==0 || n%12){ c++; n -= 111; } assert(n>0); a = b = n/12; pri({a,b,c,d}); ch({a,b,c,d},x); } } }