QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#470401#5504. Flower GardenlhzawaWA 2031ms203296kbC++144.0kb2024-07-10 12:53:232024-07-10 12:53:25

Judging History

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

  • [2024-07-10 12:53:25]
  • 评测
  • 测评结果:WA
  • 用时:2031ms
  • 内存:203296kb
  • [2024-07-10 12:53:23]
  • 提交

answer

// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
const int maxn = 2e5 + 10, maxq = 1e5 + 10, maxN = 1e6 + 10;
int n, m, N;
std::vector<int> to[maxN];
inline int newnode() {to[++N].clear(); return N;}
inline void add(int x, int y) {to[x].push_back(y);}
int id[maxn * 4][2];
void build(int k = 1, int l = 1, int r = n) {
   if (l == r) {
      for (int w : {0, 1})
         id[k][w] = l;
      return ;
   }
   int mid = (l + r) >> 1;
   build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);
   for (int w : {0, 1}) {
      id[k][w] = newnode();
      if (! w) add(id[k << 1][w], id[k][w]), add(id[k << 1 | 1][w], id[k][w]);
      else add(id[k][w], id[k << 1][w]), add(id[k][w], id[k << 1 | 1][w]);
   }
}
void add(int x, int y, int w, int u, int k = 1, int l = 1, int r = n) {
   if (x <= l && r <= y)
      return ! w ? add(id[k][w], u) : add(u, id[k][w]), void();
   int mid = (l + r) >> 1;
   if (x <= mid) add(x, y, w, u, k << 1, l, mid);
   if (mid < y) add(x, y, w, u, k << 1 | 1, mid + 1, r);
}
int dfn[maxN], low[maxN], stk[maxN], top, ins[maxN], dN;
int bl[maxN], siz[maxN], bN;
std::vector<int> son[maxN], G[maxN];
void dfs(int u) {
   dfn[u] = low[u] = ++dN, stk[++top] = u, ins[u] = 1;
   for (int v : to[u]) {
      if (! dfn[v])
         dfs(v), low[u] = std::min(low[u], low[v]);
      else if (ins[v])
         low[u] = std::min(low[u], dfn[v]);
   }
   if (low[u] < dfn[u])
      return ;
   bN++, son[bN].clear(), G[bN].clear();
   do {
      bl[stk[top]] = bN, son[bN].push_back(stk[top]), ins[stk[top]] = 0;
   } while (stk[top--] != u);
}
int deg[maxN], ord[maxN], ti[maxN];
int col[maxN], vis[maxN];
void colpre(int u) {
   if (vis[u]++) return ;
   for (int v : G[u])
      colpre(v), col[u] |= col[v];
}
void dfsc(int u) {
   if (col[u]++) return ;
   for (int v : G[u])
      dfsc(v);
}
inline void Main() {
   scanf("%d%d", &n, &m), n *= 3;
   int lim = n / 3;
   N = 0;
   for (int i = 1; i <= n; i++) newnode();
   build();
   for (int a, b, c, d; m--; ) {
      scanf("%d%d%d%d", &a, &b, &c, &d);
      int x = newnode(), y = newnode();
      add(a, b, 0, x), add(c, d, 1, y);
      add(x, y);
   }
   memset(dfn, 0, sizeof(int) * (N + 1));
   dN = bN = 0;
   for (int i = 1; i <= N; i++)
      if (! dfn[i])
         dfs(i);
   memset(siz, 0, sizeof(int) * (bN + 1));
   for (int i = 1; i <= n; i++)
      siz[bl[i]]++;
   memset(deg, 0, sizeof(int) * (bN + 1));
   for (int i = 1; i <= N; i++)
      for (int j : to[i])
         if (bl[i] != bl[j])
            G[bl[i]].push_back(bl[j]), deg[bl[j]]++;
   std::priority_queue<std::pair<int, int> > Q;
   for (int i = 1; i <= bN; i++)
      if (! deg[i])
         Q.emplace(siz[i], i);
   for (int i = 1; i <= bN; i++) {
      int u = Q.top().second; Q.pop();
      ord[i] = u, ti[u] = i;
      for (int v : G[u])
         if (! -- deg[v])
            Q.emplace(siz[v], v);
   }
   memset(col, 0, sizeof(int) * (bN + 1));
   memset(vis, 0, sizeof(int) * (bN + 1));
   for (int i = 1; i <= bN; i++) col[i] = siz[i] >= lim;
   for (int i = 1; i <= bN; i++) colpre(i);
   for (int i = bN, tot = 0; i; i--) {
      if (col[i])
         continue;
      tot += siz[ord[i]];
      if (lim <= tot && tot <= lim * 2) {
         puts("TAK");
         for (int u = 1; u <= n; u++)
            printf("%c", "RF"[ti[bl[u]] >= i && ! col[bl[u]]]);
         puts("");
         return ;
      } else if (tot > lim * 2)
         break;
   }
   for (int i = 1; i <= bN; i++) if (siz[i] >= lim) {
      memset(col, 0, sizeof(int) * (bN + 1));
      dfsc(i);
      int cnt = 0;
      for (int j = 1; j <= bN; j++)
         cnt += (col[j] > 0) * siz[j];
      if (lim <= cnt && cnt <= lim * 2) {
         puts("TAK");
         for (int u = 1; u <= n; u++)
            printf("%c", "RF"[col[bl[u]] > 0]);
         puts("");
         return ;
      }
   }
   puts("NIE");
}
int main() {
   int z; scanf("%d", &z);
   while (z--) Main();
   return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 95548kb

input:

2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1

output:

TAK
RRF
NIE

result:

ok good!

Test #2:

score: 0
Accepted
time: 1744ms
memory: 192636kb

input:

10
33333 100000
28701 40192 93418 95143
95902 97908 78378 78461
36823 44196 22268 23996
23977 24786 33315 48829
83965 90411 4923 8445
20235 21177 32543 47454
29598 35414 72477 73049
2014 12632 42163 46466
64305 65518 98825 99552
32331 41625 92772 96224
26500 54122 76990 77126
18249 20335 31165 36080...

output:

NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE

result:

ok good!

Test #3:

score: -100
Wrong Answer
time: 2031ms
memory: 203296kb

input:

10
33333 100000
15207 33614 66276 66276
97173 97173 67589 73960
19673 36626 65207 65207
89825 98169 27079 27079
56067 56966 7560 7560
18170 35477 18752 18752
32621 36748 34460 34460
61595 61700 14117 14117
32395 36710 9064 9064
13172 13172 1728 4640
40462 41878 47171 47171
76965 82414 5767 5767
9225...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

wrong answer zla odpowiedz!