Submission #120214

#TimeUsernameProblemLanguageResultExecution timeMemory
120214dantoh000JOIOJI (JOI14_joioji)C++14
95 / 100
29 ms3916 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
unordered_map<int,int> m;
int f(int x, int y){
    return (x<<17)^y;
}
main(){
    int n;
    scanf("%lld",&n);
    int ans = 0;
    int a, b;
    for (int i = 0; i < n; i++){
        char x;
        scanf(" %c",&x);
        if (x == 'J'){
            a++; b++;
        }
        else if (x == 'O') a--;
        else if (x == 'I') b--;
        int k = f(a,b);
        if (m[k] == 0){
            m[k] = i;
        }
        else{
            ans = max(ans,i-m[k]);
        }
    }
    printf("%lld",ans);

}

Compilation message (stderr)

joioji.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
joioji.cpp: In function 'int main()':
joioji.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
joioji.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c",&x);
         ~~~~~^~~~~~~~~~
joioji.cpp:17:19: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
             a++; b++;
                  ~^~
joioji.cpp:17:14: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
             a++; b++;
             ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...