QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#290855#7743. Grand FinalejeffqiCompile Error//C++202.1kb2023-12-25 17:52:542023-12-25 17:52:55

Judging History

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

  • [2023-12-25 17:52:55]
  • 评测
  • [2023-12-25 17:52:54]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define cerr if (test) cerr
#define freopen if (test) freopen
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
using namespace std;

const int test = 0;

namespace qiqi {
	constexpr int inf = 2e9,C = 26;
	const map<char,int> mp{{'Q',0},{'B',1},{'G',-1},{'W',-1}};
	void main() {
		int n,m; string s,t;
		cin >> n >> m >> s >> t;
		vector f(m+1+1,vi(n+m+1,inf));
		fill(all(f[m]),0);
		fill(all(f[m+1]),0);
		vector<array<int,2>> cnt(m+1);
		for (int i = 0; i < n; i++) {
			if (mp[s[i]-'A']) {
				cnt[0][mp[s[i]-'A']-1]++;
			}
		}
		for (int i = 0; i < m; i++) {
			cnt[i+1] = cnt[i];
			if (mp[t[i]-'A']) {
				cnt[i+1][mp[t[i]-'A']-1]++;
			}
		}
		for (int i = m-1; i >= 0; i--) {
			array<int,2> c;
			for (int j = 0; j < 2; j++) {
				c[j] = cnt[i+1][j]-cnt[i][j];
			}
			for (int j = 0; j <= n+i; j++) {
				f[i][j] = min(f[i][j],max(1,f[i+1][j+c[1]]+1-c[0]));
			}
			for (int j = 1; j <= n+i; j++) {
				f[i][j] = min(f[i][j],max(0,f[i+2][j-1+c[1]]-c[0]));
			}
		}
		vector g((m+1)/2+1,vi(m+1,0)); g[0][0] = 1;
		for (int i = 0; i <= (m+1)/2; i++) {
			for (int j = 0; j <= max(0,m-i*2); j++) {
				if (g[i][j]) {
					int k = min(m,i*2+j);
					int x = cnt[k][1]-i,y = cnt[k][0]-j;
					if (f[k][x] <= y) {
						cout << n+i << '\n';
						return;
					}
					if (x > 0) {
						g[i+1][j] = 1;
					}
					if (y > 0) {
						g[i][j+1] = 1;
					}
				}
			}
		}
		auto fail = []() {
			cout << "IMPOSSIBLE\n";
		};

		return fail();
	}
}

int main() {
	clock_t st = clock();
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T = 1;
	cin >> T;
	while (T--) {
		qiqi::main();
	}

	cerr << (double)(clock()-st)/CLOCKS_PER_SEC;
	return 0;
}

Details

answer.code: In function ‘void qiqi::main()’:
answer.code:36:40: error: passing ‘const std::map<char, int>’ as ‘this’ argument discards qualifiers [-fpermissive]
   36 |                         if (mp[s[i]-'A']) {
      |                                        ^
In file included from /usr/include/c++/11/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:81,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_map.h:512:7: note:   in call to ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = char; _Tp = int; _Compare = std::less<char>; _Alloc = std::allocator<std::pair<const char, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = char]’
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
answer.code:37:51: error: passing ‘const std::map<char, int>’ as ‘this’ argument discards qualifiers [-fpermissive]
   37 |                                 cnt[0][mp[s[i]-'A']-1]++;
      |                                                   ^
In file included from /usr/include/c++/11/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:81,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_map.h:512:7: note:   in call to ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = char; _Tp = int; _Compare = std::less<char>; _Alloc = std::allocator<std::pair<const char, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = char]’
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
answer.code:42:40: error: passing ‘const std::map<char, int>’ as ‘this’ argument discards qualifiers [-fpermissive]
   42 |                         if (mp[t[i]-'A']) {
      |                                        ^
In file included from /usr/include/c++/11/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:81,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_map.h:512:7: note:   in call to ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = char; _Tp = int; _Compare = std::less<char>; _Alloc = std::allocator<std::pair<const char, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = char]’
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
answer.code:43:53: error: passing ‘const std::map<char, int>’ as ‘this’ argument discards qualifiers [-fpermissive]
   43 |                                 cnt[i+1][mp[t[i]-'A']-1]++;
      |                                                     ^
In file included from /usr/include/c++/11/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:81,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_map.h:512:7: note:   in call to ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = char; _Tp = int; _Compare = std::less<char>; _Alloc = std::allocator<std::pair<const char, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = char]’
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
answer.code: In function ‘int main()’:
answer.code:87:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   87 |         freopen("test.in","r",stdin);
      |                ^
answer.code:88:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   88 |         freopen("test.out","w",stdout);
      |                ^