結果

問題 No.2542 Yokan for Two
ユーザー rikein12rikein12
提出日時 2023-11-24 23:46:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,879 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 205,244 KB
実行使用メモリ 23,420 KB
最終ジャッジ日時 2023-11-24 23:47:00
合計ジャッジ時間 4,633 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 13 ms
10,356 KB
testcase_04 AC 10 ms
20,104 KB
testcase_05 AC 18 ms
16,424 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 31 ms
22,616 KB
testcase_08 AC 10 ms
10,240 KB
testcase_09 AC 30 ms
22,608 KB
testcase_10 AC 6 ms
11,904 KB
testcase_11 AC 8 ms
15,988 KB
testcase_12 AC 14 ms
12,300 KB
testcase_13 AC 6 ms
13,924 KB
testcase_14 AC 33 ms
23,264 KB
testcase_15 AC 34 ms
23,420 KB
testcase_16 AC 33 ms
23,272 KB
testcase_17 AC 32 ms
23,248 KB
testcase_18 RE -
testcase_19 AC 22 ms
22,732 KB
testcase_20 AC 20 ms
22,576 KB
testcase_21 AC 20 ms
22,576 KB
testcase_22 AC 21 ms
22,716 KB
testcase_23 AC 21 ms
22,720 KB
testcase_24 AC 5 ms
6,676 KB
testcase_25 AC 6 ms
6,676 KB
testcase_26 AC 6 ms
6,676 KB
testcase_27 AC 6 ms
6,676 KB
testcase_28 AC 7 ms
8,308 KB
testcase_29 AC 10 ms
10,356 KB
testcase_30 AC 35 ms
23,164 KB
testcase_31 AC 35 ms
23,164 KB
testcase_32 AC 34 ms
23,164 KB
testcase_33 AC 35 ms
23,164 KB
testcase_34 AC 35 ms
23,164 KB
testcase_35 AC 34 ms
23,164 KB
testcase_36 AC 34 ms
23,164 KB
testcase_37 AC 34 ms
23,164 KB
testcase_38 AC 35 ms
23,164 KB
testcase_39 AC 35 ms
23,164 KB
testcase_40 AC 34 ms
23,164 KB
testcase_41 AC 35 ms
23,164 KB
testcase_42 AC 34 ms
23,164 KB
testcase_43 AC 35 ms
23,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "lib/base/base.hpp"

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define rep3(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define endl '\n'
#define all(v) (v).begin(),(v).end()

using ll = long long;

using vi = vector<int>;
using vvi = vector<vi>;

using vll = vector<ll>;
using vvll = vector<vll>;

template <class T>
using uset = unordered_set<T>;
template <class S, class T>
using umap = unordered_map<S, T>;

using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T>
using gprique = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using lprique = priority_queue<T, vector<T>, less<T>>;

const int mod998 = 998244353;
const int mod107 = 1000000007;
#line 2 "lib/utility/io.hpp"

#define INT(...) \
  int __VA_ARGS__; \
  IN(__VA_ARGS__)
#define LL(...) \
  ll __VA_ARGS__; \
  IN(__VA_ARGS__)
#define STR(...) \
  string __VA_ARGS__; \
  IN(__VA_ARGS__)
#define CHR(...) \
  char __VA_ARGS__; \
  IN(__VA_ARGS__)
#define DBL(...) \
  long double __VA_ARGS__; \
  IN(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void read(int &a) { cin >> a; }
void read(long long &a) { cin >> a; }
void read(char &a) { cin >> a; }
void read(double &a) { cin >> a; }
void read(long double &a) { cin >> a; }
void read(string &a) { cin >> a; }
template <class T, class S> void read(pair<T, S> &p) { read(p.first), read(p.second); }
template <class T> void read(vector<T> &a) {for(auto &i : a) read(i);}
template <class T> void read(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {
  read(head);
  IN(tail...);
}

template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& A) {
  os << A.first << " " << A.second;
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& A) {
  for (size_t i = 0; i < A.size(); i++) {
    if(i) os << " ";
    os << A[i];
  }
  return os;
}

template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& A) {
  int count = 0;
  os << "{";
  for(auto [t, u] : A){
    if(count) os << ", ";
    os << t << ": " << u;
    count++;
  }
  os << "}";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& A) {
  for(auto it = A.begin(); it != A.end(); ++it){
    if (it != A.begin()) os << " ";
    os << (*it);
  }
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& A) {
  size_t count = 0;
  T prev;
  os << "{";
  bool is_null = true, is_first = true;
  for(auto it = A.begin(); it != A.end(); ++it){
    if(it == A.begin()) {
      is_null = false;
      prev = (*it);
      count = 1;
    }
    if (prev != (*it)){
      if(!is_first) os << ", ";
      is_first = false;
      os << prev << ": " << count;
      prev = (*it);
      count = 1;
    } else {
      ++count;
    }
  }
  if(!is_null){
    if(!is_first) os << ", ";
    is_first = false;
    os << prev << ": " << count;
  }
  os << "}";
  return os;
}


void print() {
  cout << "\n";
  cout.flush();
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail)) cout << " ";
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"

bool DP[101][200020];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int l,n;
    IN(l,n);
    vi x(n);
    IN(x);
    int base = 100010;
    rep(j,n+2) rep3(i, base-l, base+l+1) DP[j][i] = false;
    DP[0][base] = true;
    rep(i,n+1){
        // rep3(j,base-l,base+l+1){
        //     if (DP[i][j]) print(j-base,i);
        // }            
        if (i==0){
            rep3(j,base-l,base+l+1){
                if (j - x[0]>=base-l) DP[i+1][j] = DP[i][j-x[0]];
            }            
        } else if (i==n){
            rep3(j,base-l,base+l+1){
                if (j + l - x[n-1]<=base+l) DP[i+1][j] = DP[i][j+l-x[n-1]];
            }            
        } else {
            rep3(j,base-l,base+l+1){
                if (j + x[i]-x[i-1]<=base+l) DP[i+1][j] |= DP[i][j+x[i]-x[i-1]];
                if (j - x[i]+x[i-1]>=base-l) DP[i+1][j] |= DP[i][j-x[i]+x[i-1]];
            }            
        }
    }
    int ans = l;
    // rep3(j,base-l,base+l+1){
    //     if (DP[n+1][j]) print(j-base, n);
    // }            
    rep3(i,base-l,base+l+1){
        if(DP[n+1][i]) {
            //print(i-base);
            ans = min(abs(base-i), ans);
        }
    }
    print(ans);
}

0