AtCoder Regular Contest 022

Submission #1005239

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  scanf("%d", &n);
  vi a(n);
  rep (i, n) {
    scanf("%d", &a[i]);
    a[i] -= 1;
  }
  vi state(100000, -1);
  int l = 0;
  int r = 0;
  int maxi = 0;
  for (; r < n;) {
    r += 1;
    if (state[a[r-1]] < 0) {
      state[a[r-1]] = r-1;
      maxi = max(maxi, r-l);
      continue;
    }
    int newl = state[a[r-1]] + 1;
    FOR (i, l, newl) {
      state[a[i]] = -1;
    }
    state[a[r-1]] = r-1;
    l = newl;
  }
  printf("%d\n", maxi);

  return 0;
}

Submission

Task問題 B - 細長いお菓子
User nameユーザ名 mu
Created time投稿日時
Language言語 C++11 (GCC 4.8.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1459 Byte
File nameファイル名
Exec time実行時間 31 ms
Memory usageメモリ使用量 1572 KB

Compiler messageコンパイルメッセージ

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

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
Subtask1 50 / 50 sample_01.txt,sample_02.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt
Subtask2 49 / 49 sample_01.txt,sample_02.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt
Subtask3 1 / 1 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask3_01.txt,subtask3_02.txt,subtask3_03.txt,subtask3_04.txt,subtask3_05.txt,subtask3_06.txt,subtask3_07.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 19 ms 1180 KB
sample_02.txt AC 18 ms 1184 KB
subtask1_01.txt AC 19 ms 1172 KB
subtask1_02.txt AC 20 ms 1312 KB
subtask1_03.txt AC 19 ms 1300 KB
subtask1_04.txt AC 20 ms 1180 KB
subtask1_05.txt AC 18 ms 1180 KB
subtask1_06.txt AC 19 ms 1312 KB
subtask1_07.txt AC 18 ms 1304 KB
subtask1_08.txt AC 19 ms 1180 KB
subtask1_09.txt AC 19 ms 1300 KB
subtask1_10.txt AC 18 ms 1184 KB
subtask1_11.txt AC 19 ms 1184 KB
subtask1_12.txt AC 18 ms 1228 KB
subtask2_01.txt AC 20 ms 1180 KB
subtask2_02.txt AC 19 ms 1312 KB
subtask2_03.txt AC 20 ms 1180 KB
subtask2_04.txt AC 20 ms 1188 KB
subtask2_05.txt AC 18 ms 1184 KB
subtask2_06.txt AC 18 ms 1180 KB
subtask2_07.txt AC 19 ms 1164 KB
subtask2_08.txt AC 18 ms 1312 KB
subtask2_09.txt AC 19 ms 1308 KB
subtask2_10.txt AC 19 ms 1172 KB
subtask3_01.txt AC 22 ms 1312 KB
subtask3_02.txt AC 26 ms 1396 KB
subtask3_03.txt AC 24 ms 1440 KB
subtask3_04.txt AC 31 ms 1572 KB
subtask3_05.txt AC 29 ms 1520 KB
subtask3_06.txt AC 31 ms 1564 KB
subtask3_07.txt AC 30 ms 1568 KB