QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#470300#5504. Flower GardenlhzawaWA 1978ms149092kbC++143.6kb2024-07-10 11:52:392024-07-10 11:52:39

Judging History

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

  • [2024-07-10 11:52:39]
  • 评测
  • 测评结果:WA
  • 用时:1978ms
  • 内存:149092kb
  • [2024-07-10 11:52:39]
  • 提交

answer

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

#include<bits/stdc++.h>
const int maxn = 1e5 + 10, maxq = 1e5 + 10, maxN = maxn * 3 + maxq * 2;
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];
char S[maxn];
int col[maxN];
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;
      for (int v : G[u])
         if (! -- deg[v])
            Q.emplace(siz[v], v);
   }
   for (int i = bN, tot = 0; ; i--) {
      tot += siz[ord[i]];
      if (lim <= tot && tot <= lim * 2) {
         puts("TAK");
         for (int u = 1; u <= n; u++)
            printf("%c", "RF"[ord[bl[u]] >= i]);
         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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1745ms
memory: 143504kb

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: 1978ms
memory: 149092kb

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
FFFFFFRRFRFFFFFRFFFFFRFFFFFFFFFFFFFFFRFFFFFFRFFFFFFFRFFRRFFRFFFFFRFFFFFFFFFFFFRFRFFFFRFFFRFFFFFRFFFFFFFFRFFFFFFFFFFFFFFFFFFFFFFRFFFFFFFFFFFFRFFFFFFFFFFRFFFFFFFFRFFFFFFFRFRFFFFFFFFFFRFFFFRFFFFFFFFFFFFFFFFFFFRFFFFRFFFRFFRRFFRFFFFFFFFRRFFFFFFFFFRFRFFFFFFFFFFFRRFFFFFFFFFRRFFFFRFFFFFRFRRFFRFFFFFFFFFF...

result:

wrong answer odpowiedz nie spelnia wymogow!