QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114222#6635. Strange KeyboardjeffqiCompile Error//C++232.1kb2023-06-21 16:52:372023-06-21 16:52:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-21 16:52:38]
  • 评测
  • [2023-06-21 16:52:37]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
using namespace std;
namespace qiqi {
	const int inf = 1e9,P = 1e9+7,B = 27;
	struct SH {
		int v;
		SH():(0) {}
		SH(int x):v(x) {}
		SH friend operator + (SH x,int k) {
			SH y;
			y.v = (1ll*B*x.v+k+1)%P;
			return y;
		}
		bool friend operator == (SH x,SH y) {
			return x.v == y.v;
		}
	};
	void main() {
		int n,m;
		cin >> n >> m;
		vi c(m,inf); c[0] = 0;
		vector<vector<SH>> a(n);
		for (int i = 0; i < n; i++) {
			string s; cin >> s;
			int k = sz(s);
			c[k%m] = min(c[k%m],k/m+1);
			a[i].assign(k+1,SH());
			for (int j = 0; j < k; j++) {
				a[i][j+1] = a[i][j]+(s[j]-'a');
			}
		}
		for (int i = 1; i < m; i++) {
			if (c[i] != inf) {
				int g = __gcd(i,m);
				for (int j = 0; j < g; j++) {
					for (int k = 0,x = i,y = (x+i)%m; k <= 2*m/g; k++,x = y,y = (y+i)%m) {
						c[y] = min(c[y],c[x]+c[i]+(y < x));
					}
				}
			}
		}
		struct hsh {
			size_t operator ()(const SH& x) const {
				return hash<ll>{}(1ll*x.v[0]+x.v[1]);
			}
		};
		umap<SH,int,hsh> mp;
		for (int i = 0; i < n; i++) {
			int x = sz(a[i]);
			for (int j = 1; j < x; j++) {
				int y = c[(m-(x-j-1)%m)%m]+(x-j-1+m-1)/m+1;
				if (y != inf) {
					if (mp.find(a[i][j]) == mp.end()) {
						mp[a[i][j]] = y;
					}
					else {
						mp[a[i][j]] = min(mp[a[i][j]],y);
					}
				}
			}
		}
		string s; cin >> s;
		n = sz(s);
		vi f(n+1,inf); f[0] = 0;
		for (int i = 0; i < n; i++) {
			if (f[i] != inf) {
				SH x;
				for (int j = i; j < n; j++) {
					x = x+(s[j]-'a');
					auto it = mp.find(x);
					if (it != mp.end()) {
						f[j+1] = min(f[j+1],f[i]+it->se);
					}
				}
			}
		}
		if (f[n] == inf) {
			cout << "-1\n";
			return;
		}
		cout << f[n] << '\n';
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T; cin >> T;
	while (T--) qiqi::main();
	return 0;
}

Details

answer.code: In constructor ‘qiqi::SH::SH()’:
answer.code:19:22: error: anachronistic old-style base class initializer [-fpermissive]
   19 |                 SH():(0) {}
      |                      ^
answer.code:19:21: error: unnamed initializer for ‘qiqi::SH’, which has no base classes
   19 |                 SH():(0) {}
      |                     ^
answer.code: In member function ‘size_t qiqi::main()::hsh::operator()(const qiqi::SH&) const’:
answer.code:56:58: error: invalid types ‘const int[int]’ for array subscript
   56 |                                 return hash<ll>{}(1ll*x.v[0]+x.v[1]);
      |                                                          ^
answer.code:56:65: error: invalid types ‘const int[int]’ for array subscript
   56 |                                 return hash<ll>{}(1ll*x.v[0]+x.v[1]);
      |                                                                 ^