QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572971#2519. Number with BachelorslifanCompile Error//C++142.9kb2024-09-18 16:57:312024-09-18 16:57:32

Judging History

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

  • [2024-09-18 16:57:32]
  • 评测
  • [2024-09-18 16:57:31]
  • 提交

answer

// 
//什么时候ICPC的题也开始“重视”输入输出了啊。。。。。。。
//你非要求两个进制的答案才舒服吗。。。。
#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 16) + 10;
typedef unsigned long long ull;
ull dp[2][22][maxn];
int typ, a[100];
ull dfs(int x, int sta, int limit)
{
    if (x == -1) return 1;
    int ty = (typ == 10) ? 0 : 1;
    if (dp[ty][x][sta] != -1 && !limit) return dp[ty][x][sta];
    int up = limit ? a[x] : typ - 1;
    ull ans = 0;
    for (int i = 0; i <= up; i++)
    {
        if ((sta >> i) & 1) continue;
        if (sta == 0 && i == 0) ans += dfs(x - 1, sta, limit && i == up);
        else ans += dfs(x - 1, sta | (1 << i), limit && i == up);
    }
    if (!limit) dp[ty][x][sta] = ans;
    return ans;
}
ull solve(ull x)
{
    int x = 0;
    while (x)
    {
        a[x++] = x % typ;
        x /= typ;
    }
    return dfs(x - 1, 0, true);
}
void input(ull &x)
{
    x = 0;
    char s[22];
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    for (int i = 1; i <= len; i++)
    {
        if (s[i] <= '9' && s[i] >= '0')  x = x * typ + s[i] - '0';
        else x = x * typ + s[i] - 'a' + 10;
    }
}
void print(ull x)
{
    if (x == 0)
    {
        printf("0\n");
        return;
    }
    if (typ == 10) printf("%llu\n", x);
    else
    {
        vector<int> ans;
        while (x)
        {
            int p = x % typ;
            x /= typ;
            ans.push_back(p);
        }
        for (int i = ans.size() - 1; i >= 0; i--)
        {
            if (ans[i] >= 10) printf("%c", ans[i] - 10 + 'a');
            else printf("%c", ans[i] + '0');
        }
        printf("\n");
    }
}
void test()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int x;
        scanf("%d%d", &x, &typ);
        printf("%llu", solve(x));
    }
}
int main()
{
    memset(dp, -1, sizeof(dp));
    int T;
    scanf("%d", &T);
    while (T--)
    {
        char op[10];
        scanf("%s", op);
        if (op[0] == 'd') typ = 10;
        else typ = 16;
        int flg;
        scanf("%d", &flg);
        if (!flg)
        {
            ull a, b;
            input(a), input(b);
            ull ans = solve(b);
            if (a > 0) ans -= solve(a - 1);
            print(ans);
        }
        else
        {
            ull x;
            input(x);
            if (x < 10)
            {
                printf("%llu\n", x - 1);
                continue;
            }
            ull l = 0, r = 0, ans = 0;
            r--;
            if (solve(r) < x)
            {
                printf("-\n");
                continue;
            }
            while (l <= r)
            {
                ull mid = l + (r - l) / 2;
                if (solve(mid) >= x) r = mid - 1, ans = mid;
                else l = mid + 1;
            }
            print(ans);
        }
    }
    return 0;
}

Details

answer.code: In function ‘ull solve(ull)’:
answer.code:28:9: error: declaration of ‘int x’ shadows a parameter
   28 |     int x = 0;
      |         ^
answer.code:26:15: note: ‘ull x’ previously declared here
   26 | ull solve(ull x)
      |           ~~~~^
answer.code: In function ‘void input(ull&)’:
answer.code:40:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |     scanf("%s", s + 1);
      |     ~~~~~^~~~~~~~~~~~~
answer.code: In function ‘void test()’:
answer.code:76:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   76 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
answer.code:80:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   80 |         scanf("%d%d", &x, &typ);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:88:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   88 |     scanf("%d", &T);
      |     ~~~~~^~~~~~~~~~
answer.code:92:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   92 |         scanf("%s", op);
      |         ~~~~~^~~~~~~~~~
answer.code:96:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   96 |         scanf("%d", &flg);
      |         ~~~~~^~~~~~~~~~~~