QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#853264#9738. Make It Divisibleucup-team2818#WA 0ms3776kbC++143.8kb2025-01-11 16:22:342025-01-11 16:22:40

Judging History

This is the latest submission verdict.

  • [2025-01-11 16:22:40]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3776kb
  • [2025-01-11 16:22:34]
  • Submitted

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <ctime>
#include <chrono>
#include <numeric>
#include <iomanip>
#include <cassert>

typedef long long ll;
typedef double lf;
typedef unsigned long long ull;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 5e4 + 10;

int n, a[MAXN];
int st[MAXN], top;
int pre[MAXN], nxt[MAXN];

inline bool Check(ll x)
{
    // cout << "chk " << x << '\n';
    for (int i = 1; i <= n; i++)
    {
        if (pre[i] && (a[i] + x) % (a[pre[i]] + x) != 0) return 0;
        if (nxt[i] <= n && (a[i] + x) % (a[nxt[i]] + x) != 0) return 0;
    }
    return 1;
}

int main()
{
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    int T, k;
    Read(T);
    while (T--)
    {
        Read(n), Read(k);
        int mn = 2e9;
        for (int i = 1; i <= n; i++) Read(a[i]), mn = min(mn, a[i]);
        int flag = mn;
        for (int i = 1; i <= n; i++)
            if (a[i] != mn) { flag = a[i]; break; }
        if (flag == mn)
        {
            cout << k << ' ' << (ll)k * (k + 1) / 2 << "\n";
            continue; 
        }
        st[top = 0] = 0;
        for (int i = 1; i <= n; i++)
        {
            while (top && a[st[top]] > a[i]) top--;
            pre[i] = st[top], st[++top] = i;
        }
        st[top = 0] = n + 1;
        for (int i = 1; i <= n; i++)
        {
            while (top && a[st[top]] > a[i]) top--;
            nxt[i] = st[top], st[++top] = i;
        }
        top = 0, flag -= mn;
        for (int i = 1; i * i <= flag; i++)
            if (flag % i == 0)
            {
                st[++top] = i;
                if (flag != i * i) st[++top] = flag / i;
            }
        
        int cnt = 0; ll ans = 0;
        for (int i = 1; i <= n; i++)
            if (st[i] > mn && st[i] - mn <= k && Check(st[i] - mn)) cnt++, ans += st[i] - mn;
        cout << cnt << ' ' << ans << '\n';
    }
    return 0;
}

詳細信息

Test #1:

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

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

3 8
0 0
100 5050

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3776kb

input:

4
201 1000000000
1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...

output:

0 0
1 1
0 0
0 0

result:

wrong answer 2nd lines differ - expected: '0 0', found: '1 1'