답안 #753817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753817 2023-06-06T06:17:36 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#include <sstream>
#include <fstream>
 
///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
//WAS CREAtED BY BAISYN MUKHAMMED//
///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
 
#define et "\n"
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define ioi ios::sync_with_stdio(false); cin.tie(0);  cout.tie(0)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fr for (int i = 0;i < n;i++)
#define fr1 for (int i = 1;i < n;i++)
#define Int int
 
using namespace std;
ll n,m,a1,a2,a3,ans1,ans2;
string s;
map <char,ll> mp;
pair <ll,ll> p[211111];
vector <ll> v,v1,v2;
void solve() {
	cin >> n >> m >> s;
	a1 = 0;
	for (int i = 0;i < n;i++) {
		if (s[i] == 'J' && a1 < m) {
			v.pb(i);
			a1 ++;
		}
	}
	a1 = 0;
	for(int i = 0;i < n;i++) {
		if (s[i] == 'O' && a1 < m && i > v.back()) {
			v1.pb(i);
			a1 ++;	
		}
	}
	a1 = 0;
	for (int i = 0;i < n;i++) {
		if (s[i] == 'I' && a1 < m && i > v1.back()) {
			v2.pb(i);
			a2 ++;
		}
	}
	if (v.empty() or v1.empty() or v2.empty()) {
		cout << -1 << et;return;
	}
//	for (int i = 0;i < v.size();i++) {
//		cout << v[i] << ' ';
//	}
//	for (int i = 0;i < v1.size();i++) {
//		cout << v1[i] << ' '; 
//	}
//	for (int i = 0;i < v2.size();i++) {
//		cout << v2[i] << ' ';
//	}
//	cout << et;
	for (int i = 1;i < v.size();i++) {
		ans1 += (v[i] - v[i - 1] - 1);
	}
	ans1 += v1[0] - v.back() - 1;
	for (int i = 1;i < v1.size();i++) {
		ans1 += (v1[i] - v1[i - 1] - 1);
	}
	ans1 += v2[0] - v1.back() - 1;
	for (int i = 1;i < v2.size();i++) {
		ans1 += (v2[i] - v2[i - 1] - 1);
	}
	cout << ans1;
}
int main () {
//	ioi;
//	freopen("herding.in","r",stdin);
//	freopen("herding.out","w",stdout);
	ll t = 1;
//	cin >> t;
	while (t--) {
		solve();
	}
}

Compilation message

ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for (int i = 1;i < v.size();i++) {
      |                 ~~^~~~~~~~~~
ho_t2.cpp:75:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for (int i = 1;i < v1.size();i++) {
      |                 ~~^~~~~~~~~~~
ho_t2.cpp:79:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |  for (int i = 1;i < v2.size();i++) {
      |                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -