結果
問題 | No.1515 Making Many Multiples |
ユーザー | Mister |
提出日時 | 2021-05-21 21:55:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 241 ms / 2,000 ms |
コード長 | 1,344 bytes |
コンパイル時間 | 864 ms |
コンパイル使用メモリ | 80,004 KB |
最終ジャッジ日時 | 2025-01-21 14:59:22 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> using namespace std; constexpr int INF = 1 << 30; void solve() { int n, k; cin >> n >> k; auto dp = vector(k, vector(k, -INF)); vector<int> xmax(k, -INF), ymax(k, -INF); { int x, y; cin >> x >> y; x %= k, y %= k; dp[x][y] = dp[y][x] = 0; xmax[x] = xmax[y] = 0; ymax[x] = ymax[y] = 0; } while (n--) { int x; cin >> x; x %= k; for (int i = 0; i < k; ++i) { // i+j+x=0 mod k // j=-(i+x) mod k int j = -(i + x) % k; if (j < 0) j += k; ++dp[i][j]; xmax[i] = max(xmax[i], dp[i][j]); ymax[j] = max(ymax[j], dp[i][j]); } auto pymax = ymax; for (int i = 0; i < k; ++i) { dp[i][x] = xmax[i]; ymax[x] = max(ymax[x], dp[i][x]); } for (int j = 0; j < k; ++j) { dp[x][j] = pymax[j]; xmax[x] = max(xmax[x], dp[x][j]); } } int ans = -INF; for (int i = 0; i < k; ++i) { for (int j = 0; j < k; ++j) { ans = max(ans, dp[i][j]); } } cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }