結果
| 問題 | No.434 占い |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-08 22:26:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,351 bytes |
| 記録 | |
| コンパイル時間 | 1,808 ms |
| コンパイル使用メモリ | 197,660 KB |
| 最終ジャッジ日時 | 2025-02-19 02:54:24 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 6 WA * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
using Graph = vector<vector<ll>>;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;
ll nCk(ll n,ll k){
ll res=1;
chmin(k,n-k);
rep(i,k){
res*=(n-i);
res/=(i+1);
}
if(k<0)res=0;
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll T;cin>>T;
rep(ti,T){
string s;cin>>s;
bool flg=1;
ll n=s.size();
ll ans=0;
rep(i,n){
if(s[i]!='0')flg=0;
ll x=n-1;
ll y=i;
vec u,v;
while(x){
u.push_back(x%9);
x/=9;
}
rep(j,u.size()){
v.push_back(y%9);
y/=9;
}
ll now=1;
rep(j,u.size()){
now*=nCk(u[j],v[j]);
now%=9;
}
now*=s[i]-'0';
now%=9;
ans+=now;
}
ans%=9;
if(flg==0&&ans==0)ans=9;
cout<<ans<<'\n';
}
return 0;
}