結果
問題 |
No.1349 Subset Product Queries
|
ユーザー |
👑 ![]() |
提出日時 | 2021-01-28 18:01:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 230 ms / 2,000 ms |
コード長 | 633 bytes |
コンパイル時間 | 1,883 ms |
コンパイル使用メモリ | 192,084 KB |
最終ジャッジ日時 | 2025-01-18 08:33:28 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d%d%d",&N,&Q,&P); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:13:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | rep(i,N) scanf("%d",&A[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:25:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | int l,r,k; scanf("%d%d%d",&l,&r,&k); l--; | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N,Q,P; int A[5000]; int dp[5001][5000]; int main(){ scanf("%d%d%d",&N,&Q,&P); rep(i,N) scanf("%d",&A[i]); rep(i,N+1) rep(j,P) dp[i][j]=-1; for(int i=0; i<N; i++){ int to=0; rep(p,P) dp[i+1][p]=dp[i][p]; for(int p=0; p<P; p++){ dp[i+1][to]=max(dp[i+1][to],dp[i][p]); to+=A[i]; if(to>=P) to-=P; } dp[i+1][A[i]]=i; } rep(q,Q){ int l,r,k; scanf("%d%d%d",&l,&r,&k); l--; if(dp[r][k]>=l) printf("Yes\n"); else printf("No\n"); } return 0; }