Submission #588359
Source Code Expand
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
class ABC030D{
const int bufsiz=32;
//MacPorts
//const string libgmp="/opt/local/lib/libgmp.dylib";
//ideone
//const string libgmp="/usr/lib/i386-linux-gnu/libgmp.so.10";
//paiza.io/atcoder
const string libgmp="/usr/lib/x86_64-linux-gnu/libgmp.so.10";
//wandbox/yukicoder
//const string libgmp="/usr/lib64/libgmp.so.10";
//AOJ
//const string libgmp="/usr/lib64/libgmp.so.3";
[DllImport("msvcrt",CallingConvention=CallingConvention.Cdecl)]static extern int write(int x,string y,int z);
[DllImport("msvcrt",CallingConvention=CallingConvention.Cdecl)]static extern IntPtr fopen(string x,string y);
[DllImport("msvcrt",CallingConvention=CallingConvention.Cdecl)]static extern int fflush(IntPtr x);
[DllImport("msvcrt",CallingConvention=CallingConvention.Cdecl)]static extern int puts(string x);
[DllImport("msvcrt",CallingConvention=CallingConvention.Cdecl)]static extern int system(string x);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_init(IntPtr x);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_clear(IntPtr x);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_out_str(IntPtr x,int y,IntPtr z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_set_str(IntPtr x,string y,int z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_set(IntPtr x,IntPtr y);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_set_si(IntPtr x,long y);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern int __gmpz_cmp_si(IntPtr x,long y);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_add(IntPtr x,IntPtr y,IntPtr z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_sub(IntPtr x,IntPtr y,IntPtr z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_mul(IntPtr x,IntPtr y,IntPtr z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_tdiv_q(IntPtr x,IntPtr y,IntPtr z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_tdiv_r(IntPtr x,IntPtr y,IntPtr z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_add_ui(IntPtr x,IntPtr y,long z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_sub_ui(IntPtr x,IntPtr y,long z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_mul_ui(IntPtr x,IntPtr y,long z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_tdiv_q_ui(IntPtr x,IntPtr y,long z);
[DllImport(libgmp,CallingConvention=CallingConvention.Cdecl)]static extern void __gmpz_tdiv_r_ui(IntPtr x,IntPtr y,long z);
static void Main(){
IntPtr stdout=fopen("/dev/stdout","w");
String line;
line=Console.ReadLine();
String[] ar=line.Split(' ');
int n=int.Parse(ar[0]);
int a=int.Parse(ar[1]);
line=Console.ReadLine();
IntPtr k=Marshal.AllocHGlobal(bufsiz);__gmpz_init(k);
__gmpz_set_str(k,line,10);
line=Console.ReadLine();
ar=line.Split(' ');
int[] b=new int[n+1];
for(int i=1;i<=n;i++)b[i]=int.Parse(ar[i-1]);
Dictionary<int,int>h=new Dictionary<int,int>();
int c=a;
for(int i=0;;i++){
if(h.ContainsKey(b[c])){
int cycle=i-h[b[c]];
__gmpz_tdiv_r_ui(k,k,cycle);
break;
}
c=b[c];
h[c]=i;
__gmpz_sub_ui(k,k,1);
if(__gmpz_cmp_si(k,0)==0)break;
}
for(;__gmpz_cmp_si(k,0)>0;){
c=b[c];
__gmpz_sub_ui(k,k,1);
}
Console.WriteLine(c);
__gmpz_clear(k);Marshal.FreeHGlobal(k);
}
}
Submission Info
Submission Time |
|
Task |
D - へんてこ辞書 |
User |
leafmoon |
Language |
C# (Mono 3.2.1.0) |
Score |
100 |
Code Size |
3929 Byte |
Status |
AC |
Exec Time |
212 ms |
Memory |
19508 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
All |
Score / Max Score |
0 / 0 |
50 / 50 |
50 / 50 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
subtask0_sample_01.txt, subtask0_sample_03.txt |
Subtask1 |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt, subtask0_4.txt, subtask0_5.txt, subtask0_6.txt, subtask0_7.txt, subtask0_8.txt, subtask0_9.txt, subtask0_sample_01.txt, subtask0_sample_03.txt |
All |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt, subtask0_4.txt, subtask0_5.txt, subtask0_6.txt, subtask0_7.txt, subtask0_8.txt, subtask0_9.txt, subtask0_sample_01.txt, subtask0_sample_03.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt, subtask1_sample_02.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask0_0.txt |
AC |
190 ms |
16808 KB |
subtask0_1.txt |
AC |
181 ms |
16052 KB |
subtask0_2.txt |
AC |
169 ms |
16548 KB |
subtask0_3.txt |
AC |
161 ms |
14900 KB |
subtask0_4.txt |
AC |
212 ms |
18988 KB |
subtask0_5.txt |
AC |
164 ms |
15920 KB |
subtask0_6.txt |
AC |
162 ms |
14844 KB |
subtask0_7.txt |
AC |
174 ms |
16384 KB |
subtask0_8.txt |
AC |
162 ms |
14868 KB |
subtask0_9.txt |
AC |
174 ms |
16656 KB |
subtask0_sample_01.txt |
AC |
129 ms |
9364 KB |
subtask0_sample_03.txt |
AC |
128 ms |
9356 KB |
subtask1_0.txt |
AC |
174 ms |
16000 KB |
subtask1_1.txt |
AC |
186 ms |
17188 KB |
subtask1_10.txt |
AC |
184 ms |
18444 KB |
subtask1_11.txt |
AC |
125 ms |
9356 KB |
subtask1_2.txt |
AC |
165 ms |
15660 KB |
subtask1_3.txt |
AC |
160 ms |
14636 KB |
subtask1_4.txt |
AC |
163 ms |
15204 KB |
subtask1_5.txt |
AC |
191 ms |
17700 KB |
subtask1_6.txt |
AC |
170 ms |
15024 KB |
subtask1_7.txt |
AC |
166 ms |
14244 KB |
subtask1_8.txt |
AC |
186 ms |
19156 KB |
subtask1_9.txt |
AC |
188 ms |
19508 KB |
subtask1_sample_02.txt |
AC |
127 ms |
9412 KB |