Submission #535930


Source Code Expand

#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = 1; i <= n; ++i)
#define drep(i,n) for(int i = n-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}

const int MX = 100005, INF = 1000010000;
const ll LINF = 1000000000000000000ll;
const double eps = 1e-10;



int main() {
  int n, a;
  scanf("%d%d",&n,&a);
  string s;
  cin >> s;
  vi t(n);
  rep(i,n) scanf("%d",&t[i]), t[i]--;
  --a;
  vi d;
  rep(i,n*3) {
    d.pb(a);
    a = t[a];
  }
  int c = 0;
  drep(i,sz(d)-1) {
    ++c;
    if (d[i] == d.back()) {
      break;
    }
  }
  int cs = (sz(d)-c)/c*c;
  int ans = -10;
  if (sz(s) <= 8) {
    int w = atoi(s.c_str());
    if (w < sz(d)) ans = d[w];
    else ans = d[cs+w%c];
  } else {
    int mod = 0;
    rep(i,sz(s)) {
      mod = (mod*10+(s[i]-'0'))%c;
    }
    ans = d[cs+mod];
  }
  cout<<ans+1<<endl;
  return 0;
}





Submission Info

Submission Time
Task D - へんてこ辞書
User snuke
Language C++11 (GCC 4.9.2)
Score 100
Code Size 1831 Byte
Status AC
Exec Time 59 ms
Memory 3476 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:49:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&n,&a);
                      ^
./Main.cpp:53:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   rep(i,n) scanf("%d",&t[i]), t[i]--;
                                     ^

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 50 / 50 50 / 50
Status
AC × 2
AC × 12
AC × 25
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 47 ms 3220 KB
subtask0_1.txt AC 41 ms 2196 KB
subtask0_2.txt AC 45 ms 2204 KB
subtask0_3.txt AC 40 ms 2068 KB
subtask0_4.txt AC 46 ms 3216 KB
subtask0_5.txt AC 40 ms 2204 KB
subtask0_6.txt AC 44 ms 2196 KB
subtask0_7.txt AC 45 ms 2196 KB
subtask0_8.txt AC 44 ms 2132 KB
subtask0_9.txt AC 47 ms 2192 KB
subtask0_sample_01.txt AC 25 ms 916 KB
subtask0_sample_03.txt AC 24 ms 800 KB
subtask1_0.txt AC 46 ms 2320 KB
subtask1_1.txt AC 50 ms 2324 KB
subtask1_10.txt AC 59 ms 3408 KB
subtask1_11.txt AC 25 ms 808 KB
subtask1_2.txt AC 46 ms 2200 KB
subtask1_3.txt AC 44 ms 2204 KB
subtask1_4.txt AC 45 ms 2204 KB
subtask1_5.txt AC 53 ms 2400 KB
subtask1_6.txt AC 46 ms 2328 KB
subtask1_7.txt AC 47 ms 2196 KB
subtask1_8.txt AC 56 ms 3348 KB
subtask1_9.txt AC 58 ms 3476 KB
subtask1_sample_02.txt AC 27 ms 800 KB