結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2020-12-14 14:52:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,922 bytes |
| コンパイル時間 | 968 ms |
| コンパイル使用メモリ | 90,468 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-20 00:43:43 |
| 合計ジャッジ時間 | 1,853 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 23 |
ソースコード
#pragma GCC optimize("Ofast")
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <vector>
#include <unistd.h>
#include <queue>
#include <algorithm>
using namespace std;
namespace fastio {
static constexpr int SZ = 1 << 17;
char ibuf[SZ], obuf[SZ];
int pil = 0, pir = 0, por = 0;
struct Pre {
char num[40000];
constexpr Pre() : num() {
for (int i = 0; i < 10000; i++) {
int n = i;
for (int j = 3; j >= 0; j--) {
num[i * 4 + j] = n % 10 + '0';
n /= 10;
}
}
}
} constexpr pre;
inline void load() {
memcpy(ibuf, ibuf + pil, pir - pil);
pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
pil = 0;
}
inline void flush() {
fwrite(obuf, 1, por, stdout);
por = 0;
}
inline void rd(char& c) { c = ibuf[pil++]; }
template <typename T>
inline void rd(T& x) {
if (pil + 32 > pir) load();
char c;
do
c = ibuf[pil++];
while (c < '-');
x = 0;
while (c >= '0') {
x = x * 10 + (c & 15);
c = ibuf[pil++];
}
}
inline void rd() {}
template <typename Head, typename... Tail>
inline void rd(Head& head, Tail&... tail) {
rd(head);
rd(tail...);
}
inline void wt(char c) { obuf[por++] = c; }
template <typename T>
inline void wt(T x) {
if (por > SZ - 32) flush();
if (!x) {
obuf[por++] = '0';
return;
}
int i = 12;
char buf[16];
while (x >= 10000) {
memcpy(buf + i, pre.num + (x % 10000) * 4, 4);
x /= 10000;
i -= 4;
}
if (x < 100) {
if (x < 10) {
wt(char('0' + char(x)));
} else {
uint32_t q = (uint32_t(x) * 205) >> 11;
uint32_t r = uint32_t(x) - q * 10;
obuf[por + 0] = '0' + q;
obuf[por + 1] = '0' + r;
por += 2;
}
} else {
if (x < 1000) {
memcpy(obuf + por, pre.num + (x << 2) + 1, 3);
por += 3;
} else {
memcpy(obuf + por, pre.num + (x << 2), 4);
por += 4;
}
}
memcpy(obuf + por, buf + i + 4, 12 - i);
por += 12 - i;
}
inline void wt() {}
template <typename Head, typename... Tail>
inline void wt(Head head, Tail... tail) {
wt(head);
wt(tail...);
}
template <typename T>
inline void wtn(T x) {
wt(x, '\n');
}
struct Dummy {
Dummy() { atexit(flush); }
} dummy;
} // namespace fastio
using fastio::rd;
using fastio::wt;
using fastio::wtn;
vector<int> arr(10000);
void radix_sort() {
for(int i = 0; i < 32; i++){
queue<int> queues[2];
for (unsigned j = 0; j < arr.size(); j++)
queues[(bool) (arr[j] & (1 << i))].push(arr[j]);
arr.clear();
for(int k = 0; k <= 1; k++){
while(!queues[k].empty()){
arr.push_back(queues[k].front());
queues[k].pop();
}
}
}
}
int main() {
int L;
int N;
rd(L);
rd(N);
for (int i = 0; i < N; i++) {
rd(arr[i]);
}
radix_sort();
int i;
for (i = 0; i < N; i++) {
L -= arr[i];
if (L < 0) break;
}
wtn(i);
return 0;
}