結果
| 問題 |
No.610 区間賞(Section Award)
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2017-12-10 00:08:47 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 433 ms / 2,000 ms |
| コード長 | 2,034 bytes |
| コンパイル時間 | 2,255 ms |
| コンパイル使用メモリ | 77,500 KB |
| 実行使用メモリ | 61,776 KB |
| 最終ジャッジ日時 | 2024-11-30 05:42:53 |
| 合計ジャッジ時間 | 13,091 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n=sc.nextInt();
int[]a=new int[n],b=new int[n];
for(int i=0;i<n;++i)a[i]=sc.nextInt()-1;
for(int i=0;i<n;++i)b[i]=sc.nextInt()-1;
int[]c=new int[n],d=new int[n];
for(int i=0;i<n;++i)c[b[i]]=i;
for(int i=0;i<n;++i)d[i]=c[a[i]];
int p=0;
int[]e=new int[n];
int m=n+1;
for(int i=n-1;i>=0;--i){
if(d[i]<m)
e[p++]=a[i];
m=Math.min(m,d[i]);
}
Arrays.sort(e,0,p);
for(int i=0;i<p;++i)
out.println(e[i]+1);
out.close();
}
// http://codeforces.com/blog/entry/7018
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
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;
}
}
}
夕叢霧香(ゆうむらきりか)