結果
問題 |
No.3235 巡回減算
|
ユーザー |
![]() |
提出日時 | 2025-08-16 00:51:45 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 10,000 ms |
コード長 | 1,155 bytes |
コンパイル時間 | 3,866 ms |
コンパイル使用メモリ | 313,248 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-16 00:51:51 |
合計ジャッジ時間 | 5,181 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2,tune=native") #define rep(i, n) for(int i = 0; i < n; ++i) #include <bits/stdc++.h> using namespace std; int f(int a){ int res = 0; while(a) res += a%10, a/=10; return res; } int x, y[7][8], p[1<<9], q[1<<12]; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin >> x; rep(i,7) cin >> y[i][0]; int cnt = f(x); rep(i,7) cnt -= f(y[i][0]); if(cnt){ cout << "No\n"; return 0; } rep(i,7){ rep(j,7) y[i][j+1] = y[i][j]%10*10000000 + y[i][j]/10; sort(y[i], y[i]+8); } bool ans = false; rep(a,8)rep(b,8)rep(c,8) p[a+(b<<3)+(c<<6)] = y[0][a]+y[1][b]+y[2][c]; rep(a,8)rep(b,8)rep(c,8)rep(d,8) q[a+(b<<3)+(c<<6)+(d<<9)] = y[3][a]+y[4][b]+y[5][c]+y[6][d]; sort(p,p+(1<<9)); sort(q,q+(1<<12)); for(int i=0,j=(1<<12)-1;i<(1<<9);++i){ while(j>=0 && x-p[i]<q[j]) --j; if(j>=0){ if(x-p[i]==q[j]){ ans = true; break; } }else break; } cout << (ans?"Yes\n":"No\n"); return 0; }