QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#875445#9729. Dividing SequenceMax_s_xaMWA 1ms3712kbC++173.3kb2025-01-29 19:49:132025-01-29 19:49:15

Judging History

This is the latest submission verdict.

  • [2025-01-29 19:49:15]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3712kb
  • [2025-01-29 19:49:13]
  • 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) break;
            b[++m] = mn;
            for (int i = 1; i <= n; i++)
                if (f[i]) g[i + 1] = (a[i + 1] == b[m]), flag = 1;
            if (!flag) break;
            for (int i = 1; i <= n; i++) f[i] = g[i], g[i] = 0; g[n + 1] = 0;
        }
        cout << m << "\n";
        for (int i = 1; i <= m; i++) cout << b[i] << ' '; cout << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
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 
2
3 3 
3
1 3 1 
4
2 1 3 3 

result:

ok 10 lines

Test #2:

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

input:

2000
4
2 4 4 1
1
1
3
2 3 2
4
4 4 3 1
1
1
2
3 2
4
1 3 2 1
3
4 1 1
2
4 2
4
2 3 1 2
3
3 4 3
4
1 2 2 1
2
1 1
4
1 4 2 4
2
1 3
4
4 2 4 2
5
2 4 1 4 3
4
3 4 4 3
3
1 4 4
2
1 1
5
2 1 3 2 3
4
3 2 3 4
2
1 2
1
2
4
4 1 3 2
2
1 2
4
4 2 4 4
1
3
2
2 4
1
1
1
1
1
2
4
4 4 4 3
1
1
1
1
1
4
4
1 3 2 1
2
2 1
5
3 1 1 1 1
5
4...

output:

3
2 4 4 
1
1 
2
2 3 
2
4 3 
1
1 
1
3 
3
1 3 2 
1
4 
1
4 
2
2 3 
2
3 4 
3
1 2 2 
3
1 0 2000000000 
4
1 4 2 4 
2
1 3 
1
4 
2
2 4 
3
3 4 4 
3
1 4 4 
3
1 0 2000000000 
1
2 
1
3 
2
1 2 
1
2 
1
4 
2
1 2 
1
4 
1
3 
2
2 4 
1
1 
1
1 
1
2 
2
4 4 
1
1 
1
1 
1
4 
3
1 3 2 
1
2 
1
3 
1
4 
2
2 4 
2
1 4 
1
3 
1
3 
...

result:

wrong answer 25th lines differ - expected: '1', found: '3'