답안 #582504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
582504 2022-06-24T01:18:29 Z teki JJOOII 2 (JOI20_ho_t2) C++11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
	#if LOCAL_DEBUG
		fstream cin("in.txt");
	#endif
 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	int n,k;
	cin>>n>>k;
 
	int pref[3][n+5];
	memset(pref,pref+(3*(n+5)),0);
 
	/// J pa O pa I
 
	string s;
	cin>>s;
	
	// konstruirame tabela na prefiks suma, samo go koristime brojot od prethodnata pozicija i dodavame 1 ako go ima karakterot sto go razgleduvame
	// vo ovaa implementacija, koristam vestacki prazna 0-ta pozicija za da mi bide polesno se
 
	for (int i = 0; i<n; i++) {
		pref[0][i+1] = pref[0][i] + (s[i] == 'J');
		pref[1][i+1] = pref[1][i] + (s[i] == 'O');
		pref[2][i+1] = pref[2][i] + (s[i] == 'I');
	}
 
	int curr[3];
	int res = INT_MAX/2;
 
	for (int i = 0; i<=n; i++) {
		for (int j = 0; j<3; j++) curr[j] = pref[j][i]; // go cuvame posledniot broj na karakteri od sekoj tip postojano za da moze da sporedime
 
		int newPos = i;
		int resC = 0;
 
		for (int j = 0; j<3; j++) {
			auto itJ = lower_bound(pref[j]+newPos,pref[j]+(n+1),curr[j]+k); // najdi ja slednata pozicija so +k karakteri od ovoj tip
 
			if (itJ == pref[j]+(n+1)) {resC = INT_MAX/2; break; } // ako nema, break, bidejkji nema rezultat za ovaa fiks. pozicija
 
			newPos = itJ-pref[j]; // pomesti se na slednata pozicija
 
			for (int k = 0; k<3; k++) if (k != j) resC += pref[k][newPos]-curr[k]; // dodaj ja razlikata na rezultatot
			for (int k = 0; k<3; k++) curr[k] = pref[k][newPos];
		}
 
		res = min(res,resC); // go apdejtirame konecniot rezultat
	}
 
	if (res != INT_MAX/2) cout<<res<<endl;
	else cout<<-1<<endl;
 
	return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:30: warning: 'memset' used with constant zero length parameter; this could be due to transposed parameters [-Wmemset-transposed-args]
   19 |  memset(pref,pref+(3*(n+5)),0);
      |                              ^
ho_t2.cpp:19:18: error: invalid conversion from 'int (*)[(n + 5)]' to 'int' [-fpermissive]
   19 |  memset(pref,pref+(3*(n+5)),0);
      |              ~~~~^~~~~~~~~~
      |                  |
      |                  int (*)[(n + 5)]
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/c++config.h:518,
                 from /usr/include/c++/10/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from ho_t2.cpp:1:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:59:1: note:   initializing argument 2 of 'void* memset(void*, int, size_t)'
   59 | __NTH (memset (void *__dest, int __ch, size_t __len))
      | ^~~~~