結果
問題 | No.2603 Tone Correction |
ユーザー |
![]() |
提出日時 | 2024-01-12 22:02:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,150 ms / 2,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 4,332 ms |
コンパイル使用メモリ | 253,000 KB |
最終ジャッジ日時 | 2025-02-18 18:16:33 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:17:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | rep(i,n)scanf("%lld",&a[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:18:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | rep(i,n)scanf("%lld",&b[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ long long n,m; cin>>n>>m; vector<long long> a(n),b(n); rep(i,n)scanf("%lld",&a[i]); rep(i,n)scanf("%lld",&b[i]); rep(i,n){ a[i] -= b[i]; a[i] += m; a[i] %= m; } a.insert(a.begin(),0LL); a.push_back(0); vector<long long> dp(600,Inf64); dp[dp.size()/2] = 0; for(int i=1;i<a.size();i++){ vector<long long> ndp(600,Inf64); rep(j,dp.size()){ long long x = a[i-1]; x -= m*(dp.size()/2); x += m*j; for(int k = -1;k<=1;k++){ if(j+k<0||j+k>=dp.size())continue; long long y = a[i]; y -= m*(dp.size()/2); y += m*j; y += m*k; ndp[j+k] = min(ndp[j+k],dp[j] + abs(x-y)); } } swap(dp,ndp); } long long ans = dp[dp.size()/2]; cout<<ans/2<<endl; return 0; }