結果
問題 |
No.1469 programing
|
ユーザー |
|
提出日時 | 2024-08-10 12:41:01 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 67 ms / 3,000 ms |
コード長 | 1,638 bytes |
コンパイル時間 | 4,264 ms |
コンパイル使用メモリ | 278,052 KB |
実行使用メモリ | 49,804 KB |
最終ジャッジ日時 | 2024-08-10 12:41:07 |
合計ジャッジ時間 | 5,620 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 |
ソースコード
#define PROBLEM "https://yukicoder.me/problems/no/1469" #include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> using V = std::vector<T>; #define REP(i, n) for (ll i = (ll)0; i < (ll)(n); i++) #define REPS(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++) #define RREP(i, n) for (ll i = (ll)(n); i > (ll)0; i--) #define RREPS(i, s, n) for (ll i = (ll)(n); i > (ll)(s); i--) struct io { io() { cin.tie(0)->sync_with_stdio(0); } } caller; template<typename T = char> struct RunLengthEncoding { public: RunLengthEncoding() = default; std::vector<std::pair<T, int>> encode(const std::vector<T> &v) { std::vector<std::pair<T, int>> ret; for (int i = 0; i < v.size();) { int j = i; while (j < v.size() && v[j] == v[i]) j++; ret.emplace_back(v[i], j - i); i = j; } return ret; } std::vector<std::pair<char, int>> encode(const std::string &s) { return encode(std::vector<char>(begin(s), end(s))); } std::vector<T> decode(const std::vector<std::pair<T, int>> &code) { std::vector<T> ret; for (const auto &[c, cnt]: code) { for (int i = 0; i < cnt; i++) ret.push_back(c); } return ret; } std::string decode_s(const std::vector<std::pair<char, int>> &code) { std::vector<char> v = decode(code); return std::string(begin(v), end(v)); } }; int main() { string s; cin >> s; RunLengthEncoding rle; auto code = rle.encode(s); for (const auto &[c, cnt]: code) cout << c; cout << endl; return 0; }