- 런타임 오류
에러 메시지
RTE (SIGKILL: program was forcefully killed, probably memory limit exceeded)
소스 코드
#include <cstdio>
#include <map>
#include <vector>
#include <string>
#include <memory>
#include <algorithm>
using namespace std;
struct Trie
{
struct Node
{
int next[26];
int marker;
Node() : marker(-1) { fill(next, next + 26, 0); }
};
vector<Node> nodes;
};
int main()
{
int T;
scanf("%d", &T);
for (int testcase = 1; testcase <= T; testcase++)
{
unique_ptr<char[]> buffer(new char[2030]);
scanf("%s", buffer.get());
string dat(buffer.get());
Trie t;
t.nodes.emplace_back();
int bestL = 0;
int n = dat.size();
for (int i = 0; i < n; i++)
{
int mid = dat[i] - 'a';
int limit = min(i, n - i - 1);
int nodeind = 0;
for (int j = 1; j <= limit; j++)
{
for (int k = 0; k < 2; k++) {
int cur;
if (k == 0) {
cur = dat[i - j] - 'a';
}
else {
cur = dat[i + j] - 'a';
}
int next = t.nodes[nodeind].next[cur];
if (next == 0) {
next = t.nodes[nodeind].next[cur] = t.nodes.size();
t.nodes.emplace_back();
}
nodeind = next;
}
int prevMarker = t.nodes[nodeind].marker;
if (prevMarker != -1 && prevMarker != mid)
{
bestL = max(bestL, j);
}
t.nodes[nodeind].marker = mid;
}
}
if (bestL == 0) {
puts("lonely island");
continue;
}
map<string, int> candidates;
for (int i = 0; i + bestL + 1 + bestL <= n; i++) {
string sub(dat.substr(i, bestL) + dat.substr(i + bestL + 1, bestL));
char mid = dat[i + bestL] - 'a';
candidates[sub] |= (1<<mid);
}
string answer;
for (const auto &kv : candidates)
{
int b1 = -1, b2 = -1;
for (int i = 0; i < 26; i++) {
if (kv.second & (1 << i)) {
if (b1 != -1) {
b2 = i;
break;
}
b1 = i;
}
}
if (b1 == -1 || b2 == -1)
continue;
string formatted = kv.first.substr(0, bestL);
formatted += b1 + 'a';
formatted += kv.first.substr(bestL, bestL);
formatted += " ";
formatted += kv.first.substr(0, bestL);
formatted += b2 + 'a';
formatted += kv.first.substr(bestL, bestL);
if (answer.empty() || answer > formatted) {
answer = formatted;
}
}
puts(answer.c_str());
}
return 0;
}
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int partAlange = 0;
int minValue = Integer.MAX_VALUE;
int partAsum = 0;
int partBsum = 0;
for(int j=0; j < A.length ; j++) {
for(int i=0; i < A.length ; i++) {
if(i<=partAlange) partAsum += A[i];
else partBsum += A[i];
}
minValue = Math.min(Math.abs(partAsum - partBsum), minValue);
partAsum = 0;
partBsum = 0;
partAlange++;
}
return minValue;
}
}
'살며 생각하며,' 카테고리의 다른 글
118 (0) | 2020.03.21 |
---|---|
117 (0) | 2020.03.21 |
115 (0) | 2020.03.19 |
MAC 개발자가 추천 하는 애플리케이션 - 1 (0) | 2020.03.17 |
아이폰 개발자가 추천하는 지하철 앱 (0) | 2020.03.15 |
최근댓글