結果
| 問題 |
No.2279 OR Insertion
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-21 23:59:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 2,000 ms |
| コード長 | 1,245 bytes |
| コンパイル時間 | 747 ms |
| コンパイル使用メモリ | 86,512 KB |
| 最終ジャッジ日時 | 2025-02-12 12:42:26 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 48 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d %s", &n, ib);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;
bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
bool operator()(const int& a, const int& b) {
return a<b;
}
};
#define MOD 998244353
char ib[4004];
int dp[4004];
int bb[4004];
int main() {
int n, i, ni, c;
LL b, s1, r, t;
scanf("%d %s", &n, ib);
bb[0]=1; for (i=1; i<=n; i++) bb[i]=(bb[i-1]*2)%MOD;
r=0;
for (b=0; b<n; b++) {
dp[n]=0;
s1=0;
for (i=n-1; i>=0; i--) {
if (ib[i]=='1') {
ni=i+b+1;
if (ni<=n) {
s1-=dp[ni];
c=n-ni-1; if (c<0) c=0;
s1+=bb[c];
s1%=MOD; if (s1<0) s1+=MOD;
}
}
dp[i]=s1;
// printf("dp %d,%d: %lld\n", b, i, s1);
s1+=dp[i]; s1%=MOD;
}
t=dp[0]; t*=bb[b]; t%=MOD;
r+=t; r%=MOD;
}
printf("%lld\n", r);
return 0;
}