QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#96258 | #5158. Interview Question | Zuqa# | TL | 0ms | 0kb | C++20 | 2.3kb | 2023-04-13 18:09:43 | 2023-04-13 18:09:47 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define el '\n'
#define FIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
typedef unsigned long long ull;
template<typename T, typename X>
using hashTable = gp_hash_table<T, X>;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// mt19937_64 for long long
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 1e6 + 5;
vector<int> divs[N];
int f[N], b[N], fb[N];
void pre()
{
for(int i = 1; i < N; i++)
for(int j = i; j < N; j += i)
divs[j].push_back(i);
}
void doWork()
{
int c, d, n;
cin >> c >> d, n = d - c + 1;
string in;
set<int> st;
for(int i = 1; i <= 1000000; i++)
st.insert(i);
int x = 0, y = 0, z = 0;
for(int i = c; i <= d; i++)
{
cin >> in;
if(!isalpha(in[0]))
{
int cc = stoi(in);
for(auto &it: divs[cc])
st.erase(it);
continue;
}
if(in == "Fizz")
{
x++;
for(auto &it: divs[i])
f[it]++;
}
else if(in == "Buzz")
{
y++;
for(auto &it: divs[i])
b[it]++;
}
else
{
z++;
for(auto &it: divs[i])
fb[it]++;
}
}
for(auto &i: st)
{
if(fb[i] == z)
{
for(auto &it: divs[i])
{
int p = it, q = i / it;
if(st.count(p) == 0 || st.count(q) == 0)
continue;
if(f[p] == x && b[p] == 0 && b[q] == y && f[q] == 0)
return cout << p << ' ' << q, void();
}
}
}
assert(false);
}
signed main()
{
FIO
pre();
int T = 1;
// cin >> T;
for(int i = 1; i <= T; i++)
doWork();
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
7 11 7 8 Fizz Buzz 11