답안 #282222

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282222 2020-08-24T07:11:30 Z 임성재(#5755) 기억 압축 (JOI15_memory) C++17
100 / 100
3325 ms 283952 KB
#include "Memory_lib.h"
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9 + 7;
const ll INF = 1e18;

int Memory(int N, int M) {
  if(N & 1) return -2;

  int h = M % N;
  M /= N;
  int p = M % N + 1;
  M /= N;
  int cnt = M % (N/2 + 1);
  M /= (N/2 + 1);
  int c = M % 5;

  char x = Get(p);
  if(x == '<') x = 1;
  if(x == '>') x = 2;
  if(x == '[') x = 3;
  if(x == ']') x = 4;

  if(cnt == h && (x % 2 == 1)) {
    c = x;
  }
  
  if(x == 1 || x == 3) cnt++;
  else cnt--;

  if(cnt < 0) return -2;
  if(cnt > N/2) return -2;

  if(cnt == h && (x % 2 == 0)) {
    if(c != x-1) {
      return -2;
    }
  }

  p++;
  if(p > N) {
    if(cnt != 0) return -2;

    p = 1;
    h++;
  }

  if(h >= N/2+1) {
    return -1;
  }

  int ret = 0;
  ret += c;
  ret *= (N/2 + 1);
  ret += cnt;
  ret *= N;
  ret += p-1;
  ret *= N;
  ret += h;

  return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2814 ms 283640 KB Output is correct
2 Correct 3325 ms 283896 KB Output is correct
3 Correct 3298 ms 283848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2814 ms 283640 KB Output is correct
2 Correct 3325 ms 283896 KB Output is correct
3 Correct 3298 ms 283848 KB Output is correct
4 Correct 3324 ms 283620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2814 ms 283640 KB Output is correct
2 Correct 3325 ms 283896 KB Output is correct
3 Correct 3298 ms 283848 KB Output is correct
4 Correct 3324 ms 283620 KB Output is correct
5 Correct 3185 ms 283952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2814 ms 283640 KB Output is correct
2 Correct 3325 ms 283896 KB Output is correct
3 Correct 3298 ms 283848 KB Output is correct
4 Correct 3324 ms 283620 KB Output is correct
5 Correct 3185 ms 283952 KB Output is correct
6 Correct 3198 ms 283616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3165 ms 283596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2814 ms 283640 KB Output is correct
2 Correct 3325 ms 283896 KB Output is correct
3 Correct 3298 ms 283848 KB Output is correct
4 Correct 3324 ms 283620 KB Output is correct
5 Correct 3185 ms 283952 KB Output is correct
6 Correct 3198 ms 283616 KB Output is correct
7 Correct 3165 ms 283596 KB Output is correct
8 Correct 2810 ms 283768 KB Output is correct
9 Correct 3243 ms 283808 KB Output is correct