记录编号 570384 评测结果 AAAAAAA
题目名称 [IOI 1998][USACO 3.1] 联系 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.166 s
提交时间 2022-03-29 00:28:20 内存使用 2.92 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <bitset>
#define OPEN(_x) freopen(#_x".in", "r", stdin); freopen(#_x".out", "w", stdout)
#define MAX(_a, _b) [&](int __a, int __b) { return __a < __b ? __b : __a; }((_a), (_b))
#define MIN(_a, _b) [&](int __a, int __b) { return __a > __b ? __b : __a; }((_a), (_b))
#define fi first
#define se second
 
using ll = long long;
using PII = std::pair<int, int>;
namespace IO {
    template <typename T> inline T read() {
        char ch = getchar();
        T ret = 0, sig = 1;
        while(ch < '0' || ch > '9') { if(ch == '-') sig = -1; ch = getchar(); }
        while(ch >= '0' && ch <= '9') ret *= 10, ret += ch - 48, ch = getchar();
        return ret * sig;
    }
    template <typename T> inline void write(T out) {
		if(!out) { putchar('0'); return; }
        int stk[100], tt = 0;
        if(out < 0) out = -out, putchar('-');
        while(out) stk[tt++] = out % 10, out /= 10;
        for(register int i = --tt; i>=0; --i) putchar(stk[i] + 48);
        putchar(' ');
    }
    template <typename T> inline void read(T& ret) { ret = IO::read<T>(); }
    template <typename T, typename... Args> inline void read(T& x, Args&... args) { IO::read(x), IO::read(args...); }
    template <typename T, typename... Args> inline void write(T x, Args... args)  { IO::write(x), IO::write(args...); }
};
 
 
struct Node {
    int t, v;
    std::string s;
    Node (int t, int v, std::string s):t(t), v(v), s(s) {}
};
 
const int N = 200010;
// 1, 11, 111, ..., 12x1
int ones[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095 };
int a, b, n, len;
std::vector<int> str;
std::vector<Node> ans;
std::map<std::pair<std::string, int>, int> cnt;
 
// bin to string
std::string b2s(int x, int len) {
    std::string ret;
    while (x) ret += (x & 1) + 48, x >>= 1;
    while ((int)ret.size() < len) ret += 48;
    std::reverse(ret.begin(), ret.end());
    return ret;
}
 
int main() {
    OPEN(contact);
    IO::read(a, b, n);
    char ch = getchar();
    while (ch != EOF) {
        if (ch == 48 || ch == 49) str.emplace_back(ch - 48);
        ch = getchar();
    }
    len = str.size();
    for (register int i = a; i<=b; ++i) {
        int now = 0;
        for (register int j = 0; j<len; ++j) {
            now = (now << 1) + str[j] & ones[i];
            if (j + 1 >= i) ++ cnt[{ b2s(now, i), now }];
        }
    }
    for (auto i : cnt) ans.emplace_back(i.se, i.fi.se, i.fi.fi);
    sort(ans.begin(), ans.end(), [&](Node _a, Node _b) { 
        if (_a.t == _b.t) return _a.s.size() == _b.s.size() ? _a.v < _b.v : _a.s.size() < _b.s.size();
        return _a.t > _b.t; 
            });
    int tmp = 0, cntt = 0;
    for (auto i : ans) {
        if (i.t != tmp) {
            if (++ cntt > n) break;
            tmp = i.t; 
            if (cntt == 1) printf("%d\n%s ", i.t, i.s.c_str());
            else printf("\n%d\n%s ", i.t, i.s.c_str());
        } else {
            printf("%s ", i.s.c_str());
        }
    }
    return 0;
}