QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#130682#6635. Strange KeyboardAsif17rWA 1016ms15984kbC++205.8kb2023-07-24 19:41:402023-07-24 19:41:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-24 19:41:43]
  • 评测
  • 测评结果:WA
  • 用时:1016ms
  • 内存:15984kb
  • [2023-07-24 19:41:40]
  • 提交

answer

#pragma GCC optimize("unroll-loops,O3")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
const int mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define endl '\n'
#define ll long long
typedef pair<int, int> pii;
typedef vector<int> vi;
#define in(_x) int _x; cin >> _x;
template<typename... T> void out(T&&... args) {((cout << args << " "), ...); cout << endl;}
#define inp(arr,n) vector<int>arr(n); for(auto &_a: arr) cin >> _a;
#define print(arr)  for(auto a: arr) cout << a<< " "; cout << endl;
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define mp make_pair
#define f first
#define s second
//**************OPTIONAL******************
inline int uceil(int a,int b) {int res = a/b; if(a%b and res >= 0) res++; return res;}
#define set_bit(x, idx) x = x|(1LL<<idx)
int dx[8] = {0,1,0,-1,1,-1,1,-1};
int dy[8] = {-1,0,1,0,1,1,-1,-1};
#define toggle_bit(x, idx) x = x^(1LL<<idx)
#define check_bit(x, idx) min(x&(1LL<<idx),1LL)
#define mxheap priority_queue<int>
#define mnheap priority_queue<int, vector<int>, greater<int>>
#define mxheap2 priority_queue<pair<int,int>>
#define mnheap2 priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>>
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //__gnu_cxx::sfmt19937_64  #include <ext/random>
#define rng(x,y) uniform_int_distribution<int>(x,y)(rng)
ll ulog(ll val, ll base) {ll cnt = 0; val /= base; while(val) {cnt++; val /= base;} return cnt;}
#ifdef DEBUG
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define pause(x) this_thread::sleep_for(chrono::milliseconds(x));
#define ios
#define dbg(...) {cerr << __LINE__ << " : " ;cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);}
#define ok cerr << __LINE__ << " is done " << endl;
#else
#define pause(x) 
#define ios {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define dbg(...) 
#define ok
#endif
const int inf = 1e9;
#define ll long long
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
typedef uint64_t ull;
struct H {
	ull x; H(ull _x=0) : x(_x) {}
	H operator+(H o) { return x + o.x + (x + o.x < x); }
	H operator-(H o) { return *this + ~o.x; }
	H operator*(H o) { auto m = (__uint128_t)x * o.x;
		return H((ull)m) + (ull)(m >> 64); }
	ull get() const { return x + !~x; }
	bool operator==(H o) const { return get() == o.get(); }
	bool operator<(H o) const { return get() < o.get(); }
};
static const H C = (ll)rng(1e10,1e12); // (order ~ 3e9; random also ok)

struct HashInterval {
	vector<H> ha, pw;
	HashInterval(string& str) : ha(sz(str)+1), pw(ha) {
		pw[0] = 1;
		rep(i,0,sz(str))
			ha[i+1] = ha[i] * C + str[i],
			pw[i+1] = pw[i] * C;
	}
	H hashInterval(int a, int b) { // hash [a, b)
		return ha[b] - ha[a] * pw[b - a];
	}
    void insert(char a){
        ha.pb(ha.back()*C + a);
        pw.pb(pw.back()*C);
    }
};  

void solvetc(int tt){
    in(n) in(k)
    vector<string>strs(n);
    for(auto &a: strs) cin >> a;
    string target; cin >> target;
    vector<int>singleStr(k+1, inf);
    singleStr[0] = 0;
    for(auto a: strs){
        int nw = a.size();
        singleStr[nw%k] = min(singleStr[nw%k], (nw/k)+1);
    }
    vector<int>placementDP(k+1, inf);
    placementDP[0] = 0;
    for(int i = 1; i <= k; i++){
        for(int j = 0; j < i; j++){
            placementDP[i] = min(placementDP[i], 
                    placementDP[j] + singleStr[i-j]);
        }
        dbg(i, placementDP[i]);
    }
    map<int,int>dp;
    for(string a: strs){
        HashInterval h(a);
        for(int i = 1; i <= a.size(); i++){
            int barti = a.size() - i;
            int cost = uceil(barti, k);
            barti %= k; barti = (k-barti)%k;
            if(placementDP[barti] >= inf) continue;
            cost += placementDP[barti] + 1;
            dbg(0,i,barti);
            int hash = h.hashInterval(0,i).get();
            if(dp.count(hash) == 0) {
                dp[hash] = inf;
            }
            dp[hash] = min(dp[hash], cost+1);
        }
    }
    int mx = target.size();
    vector<int>finalDP(mx+2, inf);  
    finalDP[mx] = 0;
    HashInterval keanu(target);
    for(int i = mx-1; i >= 0; i--){
        for(int j = i+1; j <= mx; j++){
            int now = keanu.hashInterval(i,j).get();
            if(dp.count(now) == 0) continue;
            now = dp[now];
            finalDP[i] = min(finalDP[i], now + finalDP[j] - 1);
            dbg(i, j, finalDP[i]);
        }
    }
    if(finalDP[0] >= inf){
        cout << -1 << endl;
    }else{
        cout << finalDP[0] << endl;
    }
}

int32_t main()
{
    ios ;
    #ifdef DEBUG  
    //~ freopen("in", "r", stdin);
    #endif
    int nn = 1;
    cin >> nn;
    rep(i,0, nn) solvetc(i+1);
}

詳細信息

Test #1:

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

input:

2
2 3
defgh
abc
abcde
1 1
a
b

output:

3
-1

result:

ok 2 number(s): "3 -1"

Test #2:

score: 0
Accepted
time: 844ms
memory: 4952kb

input:

1
1413 4867
yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn
yumnkkghwtqnhpmmsbfwypcwudihegsvt...

output:

10

result:

ok 1 number(s): "10"

Test #3:

score: 0
Accepted
time: 227ms
memory: 3980kb

input:

10
446 4905
afigcjhcgagabbiccehjcjajigghgbjjadccicghggijjdfeciaccgheedjdhgfjdfdbgidbbdjaiehhceeehchhabhaideggjbjajgfgicfdggahhbjgdebccbgbiedhehaebdccdfdffaacjcfbgjeegbahhbgcdjigijajheidchbddicehhhjbeiaajgedhdcjiefdgdbjjfaegheeidieheecaicciaajbabiidcecefgiicccdidegeica
afigcjhcgagabbiccehjcjajigghgbj...

output:

3
2
2
11
6
5
1
1
1
1

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 735ms
memory: 3712kb

input:

100
140 4879
baabaababbababbaabababaaababbbabbbbbbabbababbbabbbbabbbbbbaabbbbbbbbabaabbbaabaabbbaabbabaabaabbbabbbababbbaabbabaaaaabbaaabbbabb
baa
baabaababbababbaabababaaababbbabbbbbbabbab
baabaababbababbaabababaaabab
baabaababbababbaabababaaababbbabbb
baabaababbababbaabababaaababbbabbbbbbabbababbb...

output:

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

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 1016ms
memory: 11396kb

input:

1
7 4864
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

205

result:

ok 1 number(s): "205"

Test #6:

score: -100
Wrong Answer
time: 684ms
memory: 15984kb

input:

10
7 4923
baaabbabbbabbbbbabaabaabababbabbaaaabbaaabbbbabbaaababaaaaabaaabbabbbabbaaaabbaabbbaabbaaababaaababbabaababbaababbabaaabaabbaaabaaaababbabbabaabaabaabaabbbbaabaabbbaababbabbabaaaabbbaabbbaaaabaaaaababbaabaaaaababbbbaaaabbbaababbaabbabaabaaaaababaababaabaaaaabababababbabbbabababaaabaababbaa...

output:

-1
230
-1
549
129
372
-1
534
336
288

result:

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