QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#553285#8943. Challenge Matrix MultiplicationMax_s_xaMWA 4ms34552kbC++173.0kb2024-09-08 11:39:162024-09-08 11:39:23

Judging History

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

  • [2024-09-08 11:39:23]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:34552kb
  • [2024-09-08 11:39:16]
  • 提交

answer

#include <iostream>
#include <vector>

typedef long long ll;
typedef double lf;

// #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 = 1e6 + 10;

int n, m;
vector <int> e[MAXN];
int ind[MAXN];
bool vis[MAXN];

vector <vector <int>> pth;

int res[MAXN], f[MAXN];

int main()
{
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n), Read(m);
    for (int i = 1, u, v; i <= m; i++) Read(u), Read(v), e[u].push_back(v), ind[v]++;
    for (int i = 1; i <= n; i++)
        if (!vis[i] && e[i].size() > ind[i])
        {
            vector <int> st;
            int u = i;
            while (!st.size() || u != st.back())
            {
                st.push_back(u), vis[u] = 1;
                for (auto v : e[u])
                    if (!vis[v]) { u = v; break; }
            }
            pth.push_back(st);
        }
    for (auto st : pth)
    {
        for (int i = 1; i <= n; i++) f[i] = 0;
        for (int i = st.size() - 1; ~i; i--) f[st[i]] = st.size() - i;
        for (int i = n; i >= 1; i--)
        {
            for (auto v : e[i]) f[i] = max(f[i], f[v]);
            res[i] += f[i];
        }
    }
    for (int i = 1; i <= n; i++) cout << res[i] << ' '; cout << "\n";
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 34336kb

input:

4 6
1 3
2 3
2 4
1 2
1 3
1 3

output:

4 3 1 1 

result:

ok 4 number(s): "4 3 1 1"

Test #2:

score: 0
Accepted
time: 3ms
memory: 34552kb

input:

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

output:

4 3 2 1 1 

result:

ok 5 number(s): "4 3 2 1 1"

Test #3:

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

input:

100 900
89 90
34 35
45 46
97 98
41 42
59 61
19 20
25 29
2 3
28 29
54 55
77 78
69 74
60 61
43 44
13 14
92 93
65 66
68 69
72 73
78 81
54 56
55 60
14 15
9 10
92 93
10 11
18 19
16 17
97 98
76 77
39 40
71 72
7 8
63 64
7 8
16 24
13 24
83 84
90 91
1 4
4 5
96 97
81 82
91 92
80 81
66 67
19 20
3 4
9 10
47 48
...

output:

78 77 76 75 74 73 72 71 70 69 68 67 66 66 66 65 64 63 62 61 60 59 58 58 58 57 57 56 55 54 53 52 52 52 52 51 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 35 34 33 33 33 33 33 32 31 30 30 29 28 27 26 25 24 24 24 24 24 23 22 21 20 19 19 19 18 17 16 15 14 13 12 11 11 10 9 8 7 6 5 4 3 2 1 

result:

wrong answer 1st numbers differ - expected: '100', found: '78'