QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749890 | #7006. Rikka with Subsequences | Froranzen | AC ✓ | 551ms | 108564kb | C++17 | 7.4kb | 2024-11-15 11:10:22 | 2024-11-15 11:10:22 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, f, t) for(int i(f); i <= t; ++i)
#define re(i, t) for(int i(1); i <= t; ++i)
#define per(i, t, f) for(int i(t); i >= f; --i)
#define pe(i, t) for(int i(t); i >= 1; --i)
#define nx(i, u) for(int i(head[u]); i; i = e[i].nxt)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair <int, int> pii;
typedef long double ld;
typedef unsigned int uint;
#define pb push_back
#define eb emplace_back
#define fi first
#define eps 1e-8
#define se second
#define Ls (ix(l, mid))
#define i128 __int128
#define Rs (ix(mid+1, r))
#define ix(l, r) ((l + r) | (l != r))
#define mp(i, j) (make_pair(i, j))
// #define int __int128
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define look_memory cerr<<abs(&sT-&eD)/1024.0/1024<<'\n'
int sT;
struct IO {
#define MAXSIZE 1<<21
#define isdigit(x) (x >= '0' && x <= '9')
#define isspace(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
char ibuf[MAXSIZE], obuf[MAXSIZE], *s1, *s2, *s3, endl, blank;
int round[10] = {0, 0, 0, 0, 0, 1, 1, 1, 1}, sta[65], precisions;
bool fail;
FILE *in_stream, *out_stream;
IO(FILE *_stream = stdin, FILE *__stream = stdout) { reset(_stream,__stream); }
#if DEBUG
#else
~IO() {close();}
#endif
inline void reset (FILE *_stream = stdin, FILE *__stream = stdout, bool reset = true) {
s1 = s3 = ibuf, s2 = obuf, in_stream = _stream, out_stream = __stream, fail = false;
if(reset) { endl = '\n'; blank = ' '; precisions = 6; }
}
inline void flush_in() {s3 = (s1 = ibuf) + fread(ibuf, 1, MAXSIZE, in_stream); }
inline void flush_out() { fwrite(obuf, 1, s2-obuf, out_stream), s2 = obuf; }
inline void flush_out_with_stream() { flush_out(); fflush(out_stream); }
inline char get() {
#if DEBUG
return getchar();
#endif
return s1 == s3 && (flush_in(), fail = s1 == s3) ? 0 : *s1++;
}
inline void put(char ch) {
#if DEBUG
putchar(ch);
#else
s2-obuf == MAXSIZE ? flush_out(), 0 : 0, *s2++=ch;
#endif
}
template <class T>
inline void read(T &x) {
bool sign = false; char c = get(); x = 0;
while(!isdigit(c) && c) {sign=c=='-'; c = get(); }
while(isdigit(c)) { x = (x<<1) + (x<<3) + (c^'0'); c = get(); }
sign ? x = ~x+1 : 0;
}
inline void read(double &x) {
bool sign = false; char c = get(); x = 0;
while(!isdigit(c) && c) { sign=c=='-'; c = get(); }
while(isdigit(c)) { x = x * 10 + (c^'0'); c = get(); }
if(c=='.') { c = get(); double tmp = 1; while(isdigit(c)) { tmp /= 10, x += tmp * (c^'0'); c = get(); } }
sign ? x = -x : 0;
}
inline void read(long double &x) {
bool sign = false; register char c = get(); x = 0;
while(!isdigit(c) && c) { sign=c=='-'; c = get(); }
while(isdigit(c)) { x = x * 10 + (c^'0'); c = get(); }
if(c == '.') { c = get(); register long double tmp = 1; while(isdigit(c)) { tmp /= 10, x += tmp * (c^'0'); c = get(); } }
sign ? x = -x : 0;
}
inline void read(char *s) {
char c = get();
while(isspace(c)) c = get();
while(!isspace(c) && c) { *s++=c; c = get(); }
*s = '\0';
}
inline void read(char &c) {
do
c = get();
while(isspace(c));
}
template <class T, class ...Args>
inline void read(T &x, Args &...args) { read(x), read(args...); }
template <class T>
inline void write(T x) {
int top = 0;
if(x<0) { put('-'); sta[top++] = ~(x%10)+1, x /= 10; x = ~x+1; }
else sta[top++] = x%10, x /= 10;
while(x) sta[top++] = x%10 ,x /= 10;
while(top) put(sta[--top]^'0');
}
inline void write(double y) {
int top = 0;
if(y<0) { put('-'); y=-y; }
int x = y; y -=x;
write(x);
if(y) {
do
sta[top++] = y*10, y = y*10 - sta[top-1];
while(top<precisions-1);
sta[top++] = y*10 + round[(int)((y*10-((int)(y*10)))*10)];
}
put('.');
for(int i(0); i<top; ++i) put(sta[i]^'0');
for(int i(top); i<precisions; ++i) put('0');
}
inline void write(long double y) {
register int top = 0;
if(y<0) { put('-'); y=-y; }
int x = y; y -= x;
write(x);
if(y) {
do
sta[top++] = y*10, y = y*10 - sta[top-1];
while(top<precisions-1);
sta[top++] = y*10 + round[(int)((y*10-((int)(y*10)))*10)];
}
put('.');
for(register int i(0); i < top; ++i) put(sta[i]^'0');
for(register int i(top); i < precisions; ++i) put('0');
}
inline void write(const char ch) { put(ch); }
inline void write(char *s) { while(*s!='\0') put(*s++); }
inline void write(const char *s) { while(*s!='\0') put(*s++); }
inline void write(const std::string str) { write(str.c_str()); }
inline IO &precision(const int x) { precisions=x; return *this; }
template <class T,class ...Args>
inline void write(T x,Args ...args) { write(x), blank?put(blank), 0:0, write(args...); }
template <class ...Args>
inline void writeln(Args ...args) { write(args...), endl?put(endl), 0:0; }
template <class T>
inline IO &operator>>(T &x) { read(x); return *this; }
inline IO &operator>>(IO &x) { return *this; }
template <class T>
inline IO &operator<<(const T x) { write(x); return *this; }
inline IO &operator<<(IO &x) { return *this; }
inline operator bool() { return !fail; }
template <class T>
inline operator T() { T x; read(x); return x; }
inline void open(FILE *_stream=stdin,FILE *__stream=stdout) { close(), reset(_stream, __stream, false); }
inline void close() { flush_out_with_stream(); fclose(in_stream), fclose(out_stream); }
#define read(x) io>>x
#define out(x) io<<x
}io;
const int N = 205;
const int mod = 1e9 + 7;
int T, n, a[N], t[N][N];
char s[N][N];
int f[N][N][N], g[N][N][N], h[N][N][N];
void MOD (int &x) {
x = x >= mod ? x - mod : x;
}
void solve () {
memset(f, 0, sizeof(f));
memset(g, 0, sizeof(g));
memset(h, 0, sizeof(h));
re(i, n) re(j, n) re(k, n) if(a[i] == a[j] && a[j] == a[k]) f[i][j][k] = 1;
re(i, n) {
re(j, n) {
re(k, n) {
if(t[a[j]][a[i]]) {
g[i][j][k] += f[i-1][j][k];
}
if(a[i] == a[j]) {
h[i][j][k] += g[i][j-1][k];
}
if(a[i] == a[k]) {
f[i][j][k] += h[i][j][k-1];
}
MOD(f[i][j][k] += f[i-1][j][k]);
MOD(g[i][j][k] += g[i][j-1][k]);
MOD(h[i][j][k] += h[i][j][k-1]);
}
}
}
int ans = 0;
re(j, n) re(k, n) MOD(ans += f[n][j][k]);
io << ans << "\n";
}
int main () {
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
re(i, n) scanf("%d", &a[i]);
re(i, n) {
scanf("%s", s[i] + 1);
re(j, n) {
t[i][j] = s[i][j] - '0';
}
}
solve();
}
return 0;
}
/*
1
4
1 2 1 2
1111
1111
1111
1111
*/
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 108564kb
input:
1 4 1 2 1 2 1111 1111 1111 1111
output:
51
result:
ok single line: '51'
Test #2:
score: 0
Accepted
time: 551ms
memory: 104872kb
input:
20 195 4 5 4 3 2 4 3 5 1 5 4 3 4 3 1 5 4 4 5 2 2 2 2 4 1 5 3 4 1 1 1 2 1 1 5 5 4 5 4 5 5 4 5 2 1 2 5 4 5 1 1 3 1 2 2 3 3 5 2 3 3 1 4 4 2 4 2 4 3 4 1 1 1 4 3 5 1 1 3 2 2 5 1 3 1 5 1 5 5 3 5 3 3 2 5 1 3 2 4 1 5 5 1 3 3 2 4 2 3 3 3 4 1 3 3 3 5 5 1 1 4 2 5 1 2 5 4 3 5 1 5 5 5 4 2 2 5 3 2 3 4 1 3 2 1 5 3...
output:
806298135 541285042 48173297 222851978 875793336 100057791 156057874 129923599 551277543 874547790 544405786 653241411 521317929 370918040 803940504 969296122 806596012 469227084 338962879 194278629
result:
ok 20 lines