結果
| 問題 |
No.3247 Multiplication 8 2
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2025-08-23 00:41:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,713 bytes |
| コンパイル時間 | 2,039 ms |
| コンパイル使用メモリ | 206,908 KB |
| 実行使用メモリ | 31,636 KB |
| 最終ジャッジ日時 | 2025-08-23 00:41:10 |
| 合計ジャッジ時間 | 8,919 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 3 TLE * 1 -- * 24 |
ソースコード
#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,K;
int A[1<<20];
ll pat[1<<20];
const ll mo=998244353;
vector<int> V[1<<20];
ll modpow(ll a, ll n = mo-2) {
ll r=1;a%=mo;
while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
return r;
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>K;
FOR(i,N) cin>>A[i];
int cur=0,sgn=0;
map<pair<int,int>,ll> M;
M[{0,0}]=1;
V[0].push_back(N);
for(i=N-1;i>=0;i--) {
if(A[i]<0) sgn^=1;
if(abs(A[i])==2) cur++;
if(sgn==0&&cur%3==0&&cur>0) {
pat[i]=M[{cur-3,sgn}]%mo;
M[{cur,sgn}]+=pat[i];
V[cur/3].push_back(i);
}
}
V[cur/3].clear();
V[cur/3].push_back(0);
ll tpat=pat[0];
if(tpat==0) {
cout<<0<<endl;
return;
}
ll ret=0;
FOR(i,N/3) if(V[i].size()&&V[i+1].size()) {
ll apat=1LL*V[i].size()*V[i+1].size()%mo;
ll lef=tpat*modpow(apat)%mo;
ll sum=0;
FORR(a,V[i]) FORR(b,V[i+1]) {
sum+=modpow(a-b,K);
}
(ret+=sum%mo*lef)%=mo;
}
cout<<ret<<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;
}
kmjp