QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534367#7601. IQ TestGoldenglow1427RE 0ms3892kbC++142.6kb2024-08-27 05:15:182024-08-27 05:15:18

Judging History

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

  • [2024-08-27 05:15:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3892kb
  • [2024-08-27 05:15:18]
  • 提交

answer

/*
ID: Victor Chen [mail_vi1]
PROG: BOJ 18865
LANG: C++
*/

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

const int Maxn = 100;

ll n;

// Mapping from value to the node.
map<ll, int> mp;

map<ll, bool> exist;

// set<ll> s;

ll val[Maxn+10];
ll ans1[Maxn+10], ans2[Maxn+10];

int preCond[Maxn+10];

int nodeCount;

int cnt, head[Maxn+10];
struct Edge
{
    int to, nxt;
}p[Maxn+10];

void AddEdge(int x, int y)
{
    cnt++;
    p[cnt].to = y;

    p[cnt].nxt = head[x];
    head[x] = cnt;
}

int createNode(ll v, ll v1, ll v2)
{
    assert(nodeCount <= 45);
    assert(mp.count(v) == 0);

    val[++nodeCount] = v;
    ans1[nodeCount] = v1, ans2[nodeCount] = v2;

    mp[v] = nodeCount;
    // s.insert(v);

    return nodeCount;
}

int solve(ll x)
{
    // printf("%lld\n", x);

    if(x <= 2)
    {
        // TODO: This line is causing issues.
        // assert(0 <= x);
        return mp[x];
    }

    ll v1 = ll(ceil(sqrt(ld(x)))), v2 = v1*v1-x;
    // assert(v1 * v1 >= x);

    int pos1 = 0, pos2 = 0;

    // assert(x <= 1e18);
    
    if(mp.count(v1) == 1)
        pos1 = mp[v1];
    else
        pos1 = solve(v1);

    if(mp.count(v2) == 1)
        pos2 = mp[v2];
    else
        pos2 = solve(v2);
    
    int cur = createNode(x, v1, v2);

    AddEdge(pos1, cur);
    AddEdge(pos2, cur);

    return cur;
}

queue<int> q;

int res;

int main()
{
    mp.clear();

    scanf("%lld", &n);

    createNode(0, 0, 0);
    createNode(1, 0, 0);
    createNode(2, 0, 0);

    exist[0] = exist[1] = exist[2] = true;
    
    res = solve(n);

    assert(ans1[res]*ans1[res]-ans2[res] == n);
    assert(val[res] == n);
    
    for(int i=0; i<=2; i++)
        for(int j=head[mp[i]]; j!=0; j=p[j].nxt)
        {
            preCond[p[j].to]++;
            if(preCond[p[j].to] == 2)
                q.push(p[j].to);
        }

    while(!q.empty())
    {
        int tp = q.front();
        q.pop();

        printf("%lld %lld\n", ans1[tp], ans2[tp]);

        assert(exist[ans1[tp]]);
        assert(exist[ans2[tp]]);

        for(int i=head[tp]; i!=0; i=p[i].nxt)
        {
            preCond[p[i].to]++;
            if(preCond[p[i].to] == 2)
                q.push(p[i].to);
        }

        assert(ans1[tp]*ans1[tp]-ans2[tp] == val[tp]);
        exist[val[tp]] = true;
    }

    // TODO: This line is causing issues.
    // assert(exist[n]);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

input:

5

output:

2 0
2 1
3 4

result:

ok Successful, 3 queries

Test #2:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

7

output:

2 1
3 2

result:

ok Successful, 2 queries

Test #3:

score: -100
Runtime Error

input:

1

output:


result: