QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#96258#5158. Interview QuestionZuqa#TL 0ms0kbC++202.3kb2023-04-13 18:09:432023-04-13 18:09:47

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-13 18:09:47]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-04-13 18:09:43]
  • 提交

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

output:


result: