Open robert-min opened 1 year ago
def make_P():
for i in A:
idx = B.index(i)
answer.append(idx)
B[idx] = 0
if __name__ == "__main__":
# input
N = int(input())
A = list(map(int, input().split()))
# make B
B = sorted(A)
# make P
answer = []
make_P()
# print
for a in answer:
print(a, end=" ")
import java.io.*;
import java.util.*;
public class Main {
static FastReader scan = new FastReader();
static StringBuilder sb = new StringBuilder();
static class Elem implements Comparable<Elem> {
public int num, idx;
@Override
public int compareTo(Elem o) {
// 오름차순
return num - o.num;
}
}
static int N;
static int[] P;
static Elem[] B;
static void input() {
N = scan.nextInt();
B = new Elem[N];
P = new int[N];
for (int i=0; i < N; i++) {
B[i] = new Elem();
B[i].num = scan.nextInt();
B[i].idx = i;
}
}
static void pro() {
Arrays.sort(B); // B
// insert P
for (int i = 0; i < N; i++) {
P[B[i].idx] = i;
}
for (int i = 0; i < N; i++) {
sb.append(P[i]).append(" ");
}
System.out.println(sb.toString());
}
public static void main(String[] args) {
// input
input();
// sort and print
pro();
}
}
import sys
input = sys.stdin.readline
if __name__ == "__main__":
# input
N = int(input())
nums = []
for _ in range(N):
nums.append(int(input()))
# Counting
from collections import Counter
num_count = Counter(nums).most_common()
num_count = sorted(num_count, key= lambda x: (-x[1], x[0]))
print(num_count[0][0])
import java.io.*;
import java.util.*;
public class Main {
static FastReader scan = new FastReader();
static StringBuilder sb = new StringBuilder();
static int N;
static long[] a;
static void input() {
N = scan.nextInt();
a = new long[N + 1];
for (int i = 1; i <= N; i++) {
a[i] = scan.nextLong();
}
}
static void pro() {
// Sort 정렬하기
Arrays.sort(a, 1, N+1);
// mode: 최빈값, modeCnt: 최빈값의 등장 횟수, curCnt: 현재 값(a[1])의 등장 횟수
long mode = a[1];
int modeCnt = 1, curCnt = 1;
// 2번 원소부터 차례대로 보면서, 같은 숫자가 이어서 나오고 있는 지, 새로운 숫자가 나왔는 지를 판단하여
// curCnt를 갱신해주고, 최빈값을 갱신하는 작업.
for (int i = 2; i <= N; i++) {
if (a[i] == a[i-1]) {
curCnt++;
} else {
curCnt = 1;
}
if (curCnt > modeCnt) {
modeCnt = curCnt;
mode = a[i];
}
}
System.out.println(mode);
}
public static void main(String[] args) {
input();
pro();
}
}
import sys
input = sys.stdin.readline
def toLeft(color, i):
if i == 0:
return 100000
return a[color][i] - a[color][i-1]
def toRight(color, i):
if i + 1 == len(a[color]):
return 100000
return a[color][i+1] - a[color][i]
if __name__ == "__main__":
N = int(input())
a = [[] for _ in range(N+1)]
for i in range(N):
loc, color = map(int ,input().split())
a[color].append(loc)
ans = 0
for color in range(1, N+1):
a[color].sort()
for i in range(len(a[color])):
ans += min(toLeft(color, i), toRight(color, i))
print(ans)
import java.io.*;
import java.util.*;
public class Main {
static FastReader scan = new FastReader();
static StringBuilder sb = new StringBuilder();
static int N;
static ArrayList<Integer>[] a;
static void input() {
N = scan.nextInt();
a = new ArrayList[N + 1];
for (int color = 1; color <= N; color++) {
a[color] = new ArrayList<Integer>();
}
for (int i = 1; i <= N; i++) {
int coord, color;
coord = scan.nextInt();
color = scan.nextInt();
a[color].add(coord);
}
}
static int toLeft(int color, int idx) {
if (idx == 0) // 왼쪽에 더 이상 점이 없는 상태
return Integer.MAX_VALUE;
return a[color].get(idx) - a[color].get(idx - 1);
}
static int toRight(int color, int idx) {
if (idx + 1 == a[color].size()) // 오른쪽에 더 이상 점이 없는 상태
return Integer.MAX_VALUE;
return a[color].get(idx + 1) - a[color].get(idx);
}
static void pro() {
for (int color = 1; color <= N; color++)
Collections.sort(a[color]);
int ans = 0;
for (int color = 1; color <= N; color++) {
for (int i = 0; i < a[color].size(); i++) {
int left_distance = toLeft(color, i);
int right_distance = toRight(color, i);
ans += Math.min(left_distance, right_distance);
}
}
System.out.println(ans);
}
public static void main(String[] args) {
input();
pro();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
BOJ.10825 국영수 링크
파이썬 풀이
자바풀이