QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#462963#7302. Walk of Length 6hos_lyricAC ✓37ms12152kbC++144.6kb2024-07-04 10:29:452024-07-04 10:29:46

Judging History

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

  • [2024-07-04 10:29:46]
  • 评测
  • 测评结果:AC
  • 用时:37ms
  • 内存:12152kb
  • [2024-07-04 10:29:45]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


// PIE coef. for distinct
void pie() {
  constexpr int K = 6;
  constexpr int COEF[K + 1] = {0, +1, -1, +2, -6, +24, -120};
  vector<vector<pair<string, int>>> ess(1<<K);
  ess.back().emplace_back(string(K, '?'), 1);
  for (int p = 1<<K; --p >= 1; ) {
    const int k0 = __builtin_ctz(p);
    for (const auto &e : ess[p]) {
      for (int q = p; q; --q &= p) if (q>>k0 & 1) {
        string ss = e.first;
        for (int k = 0; k < K; ++k) if (q>>k & 1) ss[k] = '0' + k0;
        ess[p - q].emplace_back(ss, e.second * COEF[__builtin_popcount(q)]);
      }
    }
  }
  map<string, int> f;
  for (const auto &e : ess[0]) {
    bool ok = true;
    for (int k = 0; k < K; ++k) ok = ok && (e.first[k] != e.first[(k + 1) % K]);
    if (ok) {
      // cerr << e << endl;
      string mn(K, '~');
      for (const int dir : {+1, -1}) for (int rot = 0; rot < K; ++rot) {
        string s(K, '?');
        for (int k = 0; k < K; ++k) s[k] = e.first[((rot + dir * k) % K + K) % K];
        string ss(K, '?');
        char c = 'a';
        for (int k = 0; k < K; ++k) {
          for (int l = 0; l < k; ++l) if (s[k] == s[l]) {
            ss[k] = ss[l];
            break;
          }
          if (ss[k] == '?') ss[k] = c++;
        }
        chmin(mn, ss);
      }
      f[mn] += e.second;
    }
  }
  for (const auto &kv : f) if (kv.second) {
    fprintf(stderr, "ans += (%+3d) * %s();\n", kv.second, kv.first.c_str());
  }
}

constexpr int MAX = 1010;
char buf[MAX];

#define rep(u) for (int u = 0; u < N; ++u)

int N;
bitset<MAX> G[MAX];

Int deg[MAX];
Int path2[MAX][MAX];

Int ababab() {
  Int ret = 0;
  rep(a) ret += deg[a];
  return ret;
}
Int ababac() {
  Int ret = 0;
  rep(a) ret += deg[a] * deg[a];
  return ret;
}
Int ababcd() {
  Int ret = 0;
  rep(a) rep(c) ret += path2[a][c] * path2[a][c];
  return ret;
}
Int abacad() {
  Int ret = 0;
  rep(a) ret += deg[a] * deg[a] * deg[a];
  return ret;
}
Int abacbc() {
  Int ret = 0;
  rep(a) rep(b) if (G[a][b]) ret += path2[a][b];
  return ret;
}
Int abacbd() {
  Int ret = 0;
  rep(a) rep(b) if (G[a][b]) ret += path2[a][b] * path2[a][b];
  return ret;
}
Int abacdc() {
  Int ret = 0;
  rep(a) rep(d) ret += deg[a] * path2[a][d];
  return ret;
}
Int abacde() {
  Int ret = 0;
  rep(a) rep(d) ret += deg[a] * path2[a][d] * path2[a][d];
  return ret;
}
Int abcabc() {
  Int ret = 0;
  rep(a) rep(b) if (G[a][b]) ret += path2[a][b];
  return ret;
}
Int abcabd() {
  Int ret = 0;
  rep(a) rep(b) if (G[a][b]) ret += path2[a][b] * path2[a][b];
  return ret;
}
Int abcade() {
  Int ret = 0;
  rep(a) {
    Int sum = 0;
    rep(b) if (G[a][b]) sum += path2[a][b];
    ret += sum * sum;
  }
  return ret;
}

int main() {
  pie();
  
  for (; ~scanf("%d", &N); ) {
    rep(u) {
      scanf("%s", buf);
      G[u].reset();
      rep(v) if (buf[v] == '1') {
        G[u].set(v);
      }
    }
    
    rep(u) deg[u] = G[u].count();
    rep(u) rep(v) if (u <= v) path2[u][v] = path2[v][u] = (G[u] & G[v]).count();
    
    Int ans = 0;
ans += ( +4) * ababab();
ans += (-12) * ababac();
ans += ( +6) * ababcd();
ans += ( +4) * abacad();
ans += ( -3) * abacbc();
ans += ( +6) * abacbd();
ans += ( +3) * abacdc();
ans += ( -6) * abacde();
ans += ( -1) * abcabc();
ans += ( +3) * abcabd();
ans += ( -3) * abcade();
// ans += ( +1) * abcdef();
    ans = -ans;
    printf("%lld\n", ans);
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3924kb

input:

3
011
101
110
4
0101
1010
0101
1010
6
011111
101111
110111
111011
111101
111110

output:

66
128
14910

result:

ok 3 number(s): "66 128 14910"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3936kb

input:

1
0
2
01
10
3
011
100
100
3
011
101
110
4
0001
0001
0001
1110
4
0101
1001
0001
1110
4
0100
1001
0001
0110
4
0101
1011
0101
1110
4
0110
1001
1001
0110
4
0111
1011
1101
1110
5
01000
10111
01000
01000
01000
5
01111
10001
10000
10000
11000
5
01100
10110
11011
01100
00100
5
01111
10110
11010
11100
10000
...

output:

0
2
16
66
54
116
36
298
128
732
128
202
408
878
80
172
794
1372
56
372
668
190
2370
142
300
300
100
650
1216
432
4100
250
336
566
1072
988
1602
850
2648
446
1434
4438
160
264
524
1030
130
802
258
362
1380
518
1650
2372
3538
5460
488
106
234
892
1542
482
362
790
1326
2186
288
1176
1784
808
5232
7358
...

result:

ok 143 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 6212kb

input:

20
01110111111111111111
10111111111011111111
11011111101111101111
11101110111011111111
01110111111011011011
11111011101111011110
11111101111111101111
11101110111111111111
11111111011111111111
11011011101111101111
11111111110111010111
10100111111011111111
11111111111101111110
11111111111110111111
111...

output:

11368772
12823048
16678042
17149212
18099376
18616410
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
19138700
191...

result:

ok 50 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 4048kb

input:

50
01111111111101010111111110111111111111001110111111
10111111011010111101111111011111111111111111011111
11010101111111111110011110001111111111111111111111
11101111110101111110101111111111111111111101111111
11010111111101101111011111111101111111101111111110
111110111011111111111111111111111111111101...

output:

1250940348
1590514050
1984065786
2169894880
2338139630
2348971408
2399983250
2399983250
2389639440
2389639440
2399983250
2399983250
2399983250
2399983250
2399983250
2399983250
2399983250
2399983250
2399983250
2399983250

result:

ok 20 numbers

Test #5:

score: 0
Accepted
time: 37ms
memory: 11916kb

input:

1000
0110000100111110011111111011111111111111111010111011111111110111111111110111110011101111110111111110110111111111111011111100101111000111011011101111110011111101110110111011100111111101101110101111001011011101011101111101111111111111000110011011010111111111111111111010111011011110010111011111101...

output:

1943182464425962

result:

ok 1 number(s): "1943182464425962"

Test #6:

score: 0
Accepted
time: 37ms
memory: 11836kb

input:

1000
0111101111111111110111111111110011101111111101111011110111111110111011011101111110111111111111111111111111111110111110111110111101110110111111101111111111101101111111011011111111111111011111111111111111111011111111111111111110111111111111101111111101111011111111111111111111111111111000111111111...

output:

4406302098164568

result:

ok 1 number(s): "4406302098164568"

Test #7:

score: 0
Accepted
time: 34ms
memory: 11784kb

input:

1000
0111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111010111111111111111111111111111111111111111011111111111111111...

output:

7524709536316820

result:

ok 1 number(s): "7524709536316820"

Test #8:

score: 0
Accepted
time: 33ms
memory: 11832kb

input:

1000
0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

8841456311725232

result:

ok 1 number(s): "8841456311725232"

Test #9:

score: 0
Accepted
time: 34ms
memory: 11916kb

input:

1000
0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

8930014130020796

result:

ok 1 number(s): "8930014130020796"

Test #10:

score: 0
Accepted
time: 29ms
memory: 11896kb

input:

1000
0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

8930204741115000

result:

ok 1 number(s): "8930204741115000"

Test #11:

score: 0
Accepted
time: 32ms
memory: 12152kb

input:

1000
0000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

55816

result:

ok 1 number(s): "55816"

Test #12:

score: 0
Accepted
time: 31ms
memory: 11832kb

input:

1000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Extra Test:

score: 0
Extra Test Passed