Submission #64645
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | #include <bits/stdc++.h> // header {{{ /** * @brief all()マクロ */ #define all(x) std::begin(x), std::end(x) #define rall(x) std::rbegin(x), std::rend(x) /** * @brief rep()マクロ */ #define rep(i, begin, end) for (std::make_signed_t<std::remove_cv_t<decltype(end)>> i = (begin), i##_end = (end); i < i##_end; ++i) #define repc(i, begin, last) for (std::make_signed_t<std::remove_cv_t<decltype(last)>> i = (begin), i##_last = (last); i <= i##_last; ++i) #define repr(i, begin, last) for (std::make_signed_t<std::remove_cv_t<decltype(begin)>> i = (begin), i##_last = (last); i >= i##_last; --i) #define let const auto /** * @brief int-alias (整数型のエイリアス) */ using i64 = int64_t; using u64 = uint64_t; /** * @brief int-infinity (整数のデカイ値) * 2倍してもオーバーフローしない & memset()にも使える (需要ある?) */ constexpr int32_t INF = 0x3f3f3f3f; constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL; /** * @brief read() (n個入力してContainerに格納して返す) */ template < class T = int , template < class , class ...> class Container = std::vector> Container<T> read( size_t n) { Container<T> ret(n); for (auto& e : ret) std::cin >> e; return ret; } /** * @brief std::ostreamによるコンテナの出力 */ template < class Container, class = typename Container::value_type, std::enable_if_t<!std::is_same<Container, std::string>::value, std::nullptr_t> = nullptr> std::ostream& operator<<(std::ostream& os, const Container& v) { for (auto it = std::begin(v); it != std::end(v); ++it) os << & " " [it == std::begin(v)] << *it; return os; } /** * @brief 複数変数宣言をして同時に入力もするやつ */ template < class T> std::istream& operator,(std::istream& is, T& rhs) { return is >> rhs; } #define var(type, ...) \ type __VA_ARGS__; \ std::cin >> __VA_ARGS__ /** * @brief println() (可変個の値を空白区切りで出力して改行する) */ inline void println() { std::cout << '\n' ; } template < class Head, class ... Tail> inline void println(Head&& head, Tail&&... tail) { std::cout << head << & " " [! sizeof ...(tail)]; println(std::forward<Tail>(tail)...); } /** * @brief chmin(), chmax() */ template < class T, class U> inline bool chmin(T& a, const U& b) { return b < a && (a = b, true ); } template < class T, class U> inline bool chmax(T& a, const U& b) { return b > a && (a = b, true ); } /** * @brief makeVec() (多次元std::vectorの生成) */ template < class T> inline std::vector<T> makeVec( size_t sz, const T& initValue) { return std::vector<T>(sz, initValue); } template < class T, class ... Args> inline auto makeVec( size_t sz, Args... args) { return std::vector<decltype(makeVec<T>(args...))>(sz, makeVec<T>(args...)); } // }}} using namespace std; i64 f( const vector<i64>& a, const vector<i64> &b) { let N = a.size(); i64 s = 0; rep(i, 0, N) { s += abs (a[i] - b[i]); } return s; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio( false ); var( int , N); auto a = read<i64>(N); auto b = read<i64>(N); let ans1 = f(a, b); reverse(all(a)); let ans2 = f(a, b) + 1; println(min(ans1, ans2)); return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 1435 - Same Sequence |
ユーザー名 | syoribu |
投稿日時 | 2020-11-07 23:45:51 |
言語 | C++17 |
状態 | Accepted |
得点 | 3 |
ソースコード長 | 3379 Byte |
最大実行時間 | 53 ms |
最大メモリ使用量 | 3860 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 3 / 3 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 53 ms | 2780 KB |
1
|
in02.txt | AC | 42 ms | 2776 KB |
1
|
in03.txt | AC | 37 ms | 1968 KB |
1
|
in04.txt | AC | 39 ms | 2596 KB |
1
|
in05.txt | AC | 43 ms | 3552 KB |
1
|
in06.txt | AC | 46 ms | 3584 KB |
1
|
in07.txt | AC | 46 ms | 3612 KB |
1
|
in08.txt | AC | 46 ms | 3636 KB |
1
|
in09.txt | AC | 45 ms | 3660 KB |
1
|
in10.txt | AC | 40 ms | 3688 KB |
1
|
in11.txt | AC | 47 ms | 3712 KB |
1
|
in12.txt | AC | 48 ms | 3860 KB |
1
|
in13.txt | AC | 48 ms | 3748 KB |
1
|
in14.txt | AC | 20 ms | 572 KB |
1
|
in15.txt | AC | 37 ms | 3728 KB |
1
|
in16.txt | AC | 21 ms | 680 KB |
1
|
in17.txt | AC | 20 ms | 640 KB |
1
|
sample01.txt | AC | 19 ms | 724 KB |
1
|
sample02.txt | AC | 23 ms | 676 KB |
1
|