답안 #734067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734067 2023-05-01T15:48:36 Z Amaarsaa 팬케이크 정렬 (NOI12_pancake) C++14
12 / 25
23 ms 408 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
ll n, ans, p, j, s;
ll l[1002], rn[1002], r[1002];
int main() {
	ll i, t, r;
	cin >> t;
	
	while ( t --) {
		cin >> n;
		ans = 0;
		ll a[n + 2];
		vector < pair < ll, ll > > v;
		for (i = 1; i <= n; i ++) {
			cin >> a[i];
			v.push_back(make_pair(a[i], i));
		}
		sort (v.begin(), v.end());
		for ( i = 0; i < n; i ++) {
			a[v[i].second ] = i + 1;
		}
		cout << endl;
		for ( i = 1; i <= n; i ++) {
			if ( a[i] != (n - i + 1)) {
				for ( j = i; j <= n; j ++) {
					if ( a[j] == n - i + 1) r= j;
				}
				
				if ( r == n) ans ++;
				else ans += 2;
				reverse(a + r , a + n + 1);
				reverse(a + i, a + n + 1);
			}
		}
		cout << ans << endl;
	}
}

Compilation message

pancake.cpp: In function 'int main()':
pancake.cpp:33:17: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |     reverse(a + r , a + n + 1);
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 408 KB Output isn't correct
2 Halted 0 ms 0 KB -