提出 #39233132
ソースコード 拡げる
/*
_oo0oo_
o8888888o
88" . "88
(| -_- |)
0\ = /0
___/`---'\___
.' \\| |// '.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' |_/ |
\ .-\__ '-' ___/-. /
___'. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' >' "".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `_. \_ __\ /__ _/ .-` / /
=====`-.____`.___ \_____/___.-`___.-'=====
`=---='
*/
// **************************************************************************** //
// //
// ::: :::::::: //
// :+: :+: :+: //
// +:+ +:+ +:+ //
// +//+ +:+ +//+ //
// +//+//+//+//+//+ +//+ //
// //+// //+// //
// //# ########.fr //
// //
// **************************************************************************** //
#include <bits/stdc++.h>
using namespace std;
//#define s(n) scanf("%d",&n)
#define s2(a,b) scanf("%d%d",&a,&b)
#define s3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc(n) scanf("%c",&n)
#define sl(n) scanf("%I64d",&n)
#define sf(n)
//----------------------------------------------- --------------------------------------------
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using str = string;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); ++(i))
#define REP(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int (i) = (b)-1; (i) >= (a); --(i))
#define PER(i,a) ROF(i,0,a)
#define rep(a) REP(_,a)
#define each(a,x) for (auto& a: x)
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);} //__gcd
ll lcm(ll a, ll b){return (a/gcd(a,b)*b);}
ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)res = (res + a) % mod;b >>= 1;}return res;}
ll powermod(ll x, ll y, ll p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
bool isPrime(ll n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
bool isPowerOfTwo(int n){if(n==0)return false;return (ceil(log2(n)) == floor(log2(n)));}
bool isPerfectSquare(ll x){if (x >= 0) {ll sr = sqrt(x);return (sr * sr == x);}return false;}
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18;
const db PI = acos((db)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem
tcT> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0; }
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
sort(all(v)); v.erase(unique(all(v)),end(v)); }
// Some Codes Skipped
inline namespace FileIO {
void setIn(str s) {freopen(s.c_str(),"r",stdin);}
void setOut(str s) {freopen(s.c_str(),"w",stdout);}
void setIO(str s = "") {
cin.tie(0)->sync_with_stdio(0); // unsync C / C++ I/O streams
// cin.exceptions(cin.failbit);
// throws exception when do smth illegal
// ex. try to read letter into int
if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for old USACO
}
}
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Sudhir cout.tie(NULL);
#define vll vector<long long int>
const int NUM = 31;
#define int long long
#define intd long double
#define pi 3.141592653589793238
#define ff first
#define ss second
#define umap unordered_map<int, int>
#define vi vector<int>
#define pii pair<int, int>
#define all1(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define allr1(v) (v).rbegin()+1,(v).rend()
#define sort0(v) sort(all(v))
#define setBits(x) __builtin_popcount(x)
#define pb push_back
#define ppb pop_back
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> > #define ini(a, i) memset(a, i, sizeof(a))
// #define lb lower_bound #define ub upper_bound
#define py cout<<"YES\n"; #define pm cout<<"-1\n";
#define pn cout<<"NO\n"; #define ASCII_SIZE 256
#define pb push_back
#define fr(a,b) for(int i = a; i < b; i++)
#define mod 1000000007 #define inf (1LL<<60) #define prDouble(x) cout << fixed << setprecision(10) << x #define triplet pair<ll,pair<ll,ll>>
#define echo(p) cout << p <<endl;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define read(x) int x; cin >> x;
#define reads(x) string x; cin >> x;
using namespace std;
void init_code(){
fast_io;
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
// s1 + rev(s2)
// check if s[i]==s[i+1] count >1 cout<< NO else YES
void solvve(){
int n, x = 0, y = 0;
cin >> n;
string s;
cin >> s;
set<pair<int,int>> visited;
visited.insert({0,0});
for(int i = 0; i < n; i++) {
if(s[i] == 'R') x++;
else if(s[i] == 'L') x--;
else if(s[i] == 'U') y++;
else y--;
if(visited.count({x,y}) > 0) {
cout << "Yes" << endl;
return ;
}
visited.insert({x,y});
}
cout << "No" << endl;
}
signed main()
{
init_code();
// read(t)
// while (t--) {
solvve();
// cout<<endl;
return 0;
}
提出情報
コンパイルエラー
./Main.cpp: In function ‘void FileIO::setIn(str)’:
./Main.cpp:131:31: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
131 | void setIn(str s) {freopen(s.c_str(),"r",stdin);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
./Main.cpp: In function ‘void FileIO::setOut(str)’:
./Main.cpp:132:32: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
132 | void setOut(str s) {freopen(s.c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
300 / 300 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt, sample_02.txt |
| All |
hand.txt, hand_01.txt, hand_02.txt, min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| hand.txt |
AC |
44 ms |
16092 KiB |
| hand_01.txt |
AC |
49 ms |
16104 KiB |
| hand_02.txt |
AC |
27 ms |
8640 KiB |
| min.txt |
AC |
2 ms |
3616 KiB |
| random_01.txt |
AC |
3 ms |
3792 KiB |
| random_02.txt |
AC |
3 ms |
3680 KiB |
| random_03.txt |
AC |
2 ms |
3720 KiB |
| random_04.txt |
AC |
3 ms |
3752 KiB |
| random_05.txt |
AC |
4 ms |
3628 KiB |
| random_06.txt |
AC |
2 ms |
3608 KiB |
| random_07.txt |
AC |
53 ms |
15996 KiB |
| random_08.txt |
AC |
18 ms |
7168 KiB |
| random_09.txt |
AC |
47 ms |
16044 KiB |
| random_10.txt |
AC |
15 ms |
6772 KiB |
| random_11.txt |
AC |
48 ms |
16004 KiB |
| random_12.txt |
AC |
10 ms |
5216 KiB |
| random_13.txt |
AC |
3 ms |
3792 KiB |
| random_14.txt |
AC |
3 ms |
3512 KiB |
| random_15.txt |
AC |
4 ms |
3732 KiB |
| random_16.txt |
AC |
5 ms |
3628 KiB |
| random_17.txt |
AC |
3 ms |
3612 KiB |
| random_18.txt |
AC |
2 ms |
3632 KiB |
| random_19.txt |
AC |
3 ms |
3604 KiB |
| random_20.txt |
AC |
3 ms |
3612 KiB |
| random_21.txt |
AC |
7 ms |
3624 KiB |
| random_22.txt |
AC |
4 ms |
3708 KiB |
| random_23.txt |
AC |
84 ms |
16044 KiB |
| random_24.txt |
AC |
80 ms |
16116 KiB |
| random_25.txt |
AC |
82 ms |
16008 KiB |
| random_26.txt |
AC |
82 ms |
15992 KiB |
| random_27.txt |
AC |
80 ms |
16136 KiB |
| random_28.txt |
AC |
77 ms |
16000 KiB |
| random_29.txt |
AC |
80 ms |
16140 KiB |
| random_30.txt |
AC |
81 ms |
16132 KiB |
| random_31.txt |
AC |
73 ms |
16012 KiB |
| random_32.txt |
AC |
60 ms |
12260 KiB |
| sample_01.txt |
AC |
4 ms |
3500 KiB |
| sample_02.txt |
AC |
2 ms |
3532 KiB |