QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875447#9729. Dividing SequenceMax_s_xaMWA 1ms3712kbC++173.3kb2025-01-29 19:52:252025-01-29 19:52:25

Judging History

This is the latest submission verdict.

  • [2025-01-29 19:52:25]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3712kb
  • [2025-01-29 19:52:25]
  • 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 = 5e3 + 10;

int n, a[MAXN], m, b[MAXN];

int f[MAXN], g[MAXN];

int main()
{
    #ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    int T;
    Read(T);
    while (T--)
    {
        Read(n);
        for (int i = 1; i <= n; i++) Read(a[i]);
        for (int i = 1; i <= n + 1; i++) f[i] = g[i] = 0; a[n + 1] = 0;
        b[m = 1] = a[1], f[1] = 1;
        while (1)
        {
            bool flag = 0; int mn = 2e9;
            for (int i = 1; i < n; i++)
                if (f[i])
                {
                    int p = i - m + 1;
                    if (p <= m && a[i + 1] < b[p]) { flag = 1; break; }
                    if (p <= m && a[i + 1] == b[p]) f[i + 1] = 1;
                    mn = min(mn, a[i + 1]);
                }
            if (flag || mn == 2e9) break;
            b[++m] = mn;
            for (int i = 1; i < n; i++)
                if (f[i]) g[i + 1] = (a[i + 1] == b[m]);
            for (int i = 1; i <= n; i++) f[i] = g[i], g[i] = 0;
        }
        cout << m << "\n";
        for (int i = 1; i <= m; i++) cout << b[i] << ' '; cout << "\n";
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3712kb

input:

5
5
3 1 2 3 2
3
1 1 2
3
3 3 3
5
1 3 1 3 1
5
2 2 1 3 3

output:

1
3 
3
1 1 2 
3
3 3 3 
5
1 3 1 3 1 
4
2 1 3 3 

result:

wrong answer 5th lines differ - expected: '2', found: '3'